1

Suppose, I have a parent folder which includes 4 sub-folders. Each of the sub-folders can have a different number of subfolders (let's call them sub-sub-folders). How do I move all sub-sub-folders into the parent folder and delete all sub-folders bash?

For now, I am using the following command:

find . -mindepth 2 -type d -print -exec mv {} . \;

1 Answer 1

0

I think you're almost there, but what your command does is moving everything below depth 2, so you need to limit the maxdepth as well:

find . -mindepth 2 -maxdepth 2 -type d -print -exec mv {} . \;

Since you're moving them you don't need to delete anything.

1
  • To remove the now empty sub-folders, the following could be done: find . -maxdepth 1 -type d -empty -print -exec rmdir {} + But this removes all empty dirs, not the original sub-folders only, which would require a two stage moving.
    – MichaIng
    Nov 20, 2020 at 1:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .