Frage

If I have a directory tree that looks like this:

parent/
   child/
      many files

What command/commands should I use to quickly make it like this:

parent/
   many files

Effectively, I just want to remove one level of folder nesting. I don't care about any other files currently in parent.

War es hilfreich?

Lösung

This is what you do:

cd parent
mv child/* .
rmdir child

If you have files beginning with . (dot) in the child/ directory, you have to do

shopt -s dotglob

in order for the * to match them (there are other ways to force this, but setting dotglob is the easiest).

If child/ contains a file or directory named child, then you have to either rename that or the directory parent/child before the mv operation.

Andere Tipps

What about this?

mkdir new
find parent -type f -exec mv {} new/. \;

That would work for any depth of directory.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top