How to copy all files recursively excluding folders into one destination folder?
The find
command will find all files of the specified pattern (-name), in this case a specific file type: *.mp3
. -exec
makes all following arguments to find to be taken as arguments to the command until an argument consisting of ;
is encountered (at the end, with literal escape to prevent expansion by the shell). In this case, the command we wish to execute is a file copy (cp
) on files that match pattern ({}
) and copy those files to /destination_dir
. This command should do the trick:
find /music -name "*.mp3" -type file -exec cp {} /destination_dir \;
If you have installed Bash 4, you could add shopt -s globstar
to .bash_profile and run this:
cp /music/**/*.mp3 /musicTemp/