15

I want to copy all files in ~/Desktop with the extension .jpeg to my flash drive.

How can I do this in the terminal?

2 Answers 2

17
cp ~/Desktop/*.jpeg /Volumes/flashdrive/

will copy all of the files on the current user's desktop with extension ".jpeg" to the drive named "flashdrive".

If the above command produces an Argument list too long error, then the safest most efficient way to handle it is to use a for loop like this:

for f in ~/Desktop/*.jpeg; do cp "$f" /Volumes/flashdrive/; done
9

Try:

find /source/directory -iname \*.jpeg -exec cp {} /destination/directory/ \;

Where /source/directory is would be your /Users/*username*/Desktop/ directory.

Answer provided from Stack Overflow

2
  • 4
    a simple cp ~/Desktop/*.jpeg /flashdrive is slightly less scary for a Terminal newbie...
    – MattDMo
    Jun 20, 2013 at 14:36
  • This worked when the other answer gave me an "Argument list too long" error for ~60k files.
    – fzwo
    Apr 13, 2016 at 15:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .