Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have several folders like /music/1/a.mp3 and /music/2/b.mp3

All of the file names themselves are guaranteed to be different.

Is there a way, probably using the Terminal, to copy these files to /musicTemp/ excluding the folders?

In other words, the result of the two examples above should be:



share|improve this question
Does Finder provide an option to search for files recursively? If yes, search, select all, and drag to your destination. I know that's a good option on other OSes. – Ben Voigt Mar 7 '13 at 21:51
That's so obvious I just facepalmed. All files are .m4a and Finder lets me limit to just /music/. Thanks!!! – samiles Mar 7 '13 at 21:52
Just to add an alternative: find /music -name "*.mp3" -type file -exec mv {} /destination_dir \; – Hennes Mar 7 '13 at 21:54
@Hennes: cp not mv. Otherwise that should work. – Ben Voigt Mar 7 '13 at 21:59

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 \;
share|improve this answer

If you have installed Bash 4, you could add shopt -s globstar to .bash_profile and run this:

cp /music/**/*.mp3 /musicTemp/
share|improve this answer
Not sure what shopt.. is necessary for as this works without mods, also with mv.. Thanks anyhow the ** is new to me :) – geotheory Mar 26 '15 at 15:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.