Shell – How to condense subdirectories

directoryshell-script

I have one directory with many sub-directories. All of those sub-directories contain files which each have unique names. I want to take all the files from all of the sub-directories and move them all to one directory.

There are a few hundred sub-directories, so I wouldn't want to do this by hand. How would I go about writing a shell script to do this? I'm using bash.

Best Answer

find is the solution:

find /srcpath -type f -exec mv {} /dstpath \;

or better, if your mv has the -t destination-dir option:

find /srcpath -type f -exec mv -t /dstpath {} +
Related Question