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 need a unix command for the following:

Directory Structure


I would like one command to copy all files* not folders out of the "images" directory recursively to something like this.


I tried this but it just copied the folders recursively cp -r ./project/images/* ./assets/

share|improve this question
I just found this and it works find project -type f -exec cp {} assets \; – ThomasReggi Apr 23 '13 at 17:45
Please post your solution as an answer. Answering your own questions is not only accepted but encouraged. I would recommend, however, that you quote {} so you won't have trouble with file names with spaces: find project/images -type f -exec cp '{}' assets \; – terdon Apr 23 '13 at 21:25
@terdon {} does not have to be quoted. – user495470 Apr 24 '13 at 0:27
@LauriRanta I stand corrected, thanks. – terdon Apr 24 '13 at 0:49

This executes cp for every file, so it can be noticeably slower if there are many small files (but not with typical images):

find project -name \*.jpg -exec cp {} assets \;

This takes multiple arguments at a time:

find project -name \*.jpg -print0 | xargs -0 -I% cp % assets

Without -0 filenames that contain single quotes or double quotes would result in an error like xargs: unterminated quote.

Bash 4 supports ** with shopt -s globstar:

cp project/**/*.jpg assets
share|improve this answer

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.