Sometimes, we note that we have unused nested containers (directories) .
For example :
mkdir -p ~/grandpa/pa;
And pa
directory is the only file existed on grandpa
.
Hence, all files of pa
should be moved to grandpa
, then pa
will be deleted.
My question is there is a built-in command line do such a mission:
i.e:
orphan ~/grandpa/pa/*
or
fatherless ~/grandpa/pa/*
You can just use standard bash commands -
mv
,rm
, etc - for exampleThis:
mv
to move the files in~/grandpa/pa/*
to~/grandpa/
&&
so the rmdir command only if themv
exits successfully -;
could be used..rmdir
to remove thepa
directory if it is empty.N.B. tested on the directory structure - before:
after: