About Me

My photo
Drum & Bass Producer, Software Developer, Love my Cats

[mac os x tutorial] How to FLATTEN a directory or folder using the Terminal command

If you have a folder with many subfolders that you want to FLATTEN, meaning, move all the sub or sub-sub-folders' content into the root folder.
Open the Mac OS X Terminal and cd your way into the folder you want to be the root folder.
for example:
cd ~/Desktop/my-folder

And then run this command, AFTER changing 2 places where it says [DIRECTORY] to your current directory path (if there are spaces in the path, wrap the whole path with "s):

find [DIRECTORY] -mindepth 2 -type f -exec mv -i '{}' [DIRECTORY] ';'

eg, it will look like this:
find ~/Desktop/my-folder -mindepth 2 -type f -exec mv -i '{}' ~/Desktop/my-folder ';'

Hope this little script helps you flatten mac os x directories or indented sub folder hierarchy into a flat structure!