Ubuntu – How to move all files in subdirectories recursively to a single directory

command linefind

I am trying to collect all the files under the current directory and all the subdirectories to one directory. I am trying something like the following

find -type f -exec mv {} collection/{} \; 

the above command won't work because the second {} gives the full path, how can I collect all the files?

Best Answer

Remove the {} from mv, mv will take it as target directory ignoring any parent directories:

find -type f -exec mv {} collection/ \;