Is it possible to use mv or cp commands to collect all photos from multiple subfolders to target folder rec_all via one command in terminal?

I have about 400 subfolders! Each of them have hundreds of photos like .jpg! Subfolders names are rec_pho.1 to rec_pho.400. Target folder is rec_all.


Actually yeah, (your syntax will depend though) :

cp -r Pictures/rec_pho.*/*.jpg Pictures/rec_all/
  • Do you need the -rf flags? – wjandrea Mar 25 '19 at 15:16
  • I'm just thinking is it necessary and I'm testing this command: cp Pictures/rec_pho.*/*.jpg Pictures/rec_all/ – Jari Mar 25 '19 at 16:27
  • I just checked destination folder "rec_all" from nautilus and it looks that it works! Thanks a lot! :) – Jari Mar 25 '19 at 16:31
  • @wjandrea -r is for recursive usefull in this case. when I tested in on a couple folders with logs, some had the same name, so -f made it so that the new copied files would crush the older. this is at the user's discretion, personally I prefer ham-fisted approaches to these sort of problems. considering cameras generally put the date and time in the picture's name this would fuze them. I removed the -f as I can see why this could be quote-unquote dangerous. – tatsu Mar 25 '19 at 16:32
  • 1
    @Jari if this worked for you, could you mark as answer and upvote please? – tatsu Mar 25 '19 at 16:33

use the -t option

cd /root/directory/for/photos
# mv -t /destination/directory */*.jpg
cp -t /destination/directory */*.jpg


  • 1
    oh! better than mine, have an upvote! (issue is you should make a backup of folder first if preserving the hiarchy is of any use later) – tatsu Mar 25 '19 at 15:02
  • 1
    Just to be extra clear, for OP's case it would be cp -t rec_all rec_pho.*/*.jpg – wjandrea Mar 25 '19 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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