So I recovered all the files that were still available on a corrupted external drive using testdisk. Now I want to sort out the different file extensions and copy them to their respective newly created main directories (.jpg / .doc / .xls etc...)

After some looking around I found that the following entry in the commandline should do the trick, however I get a message stating there is a missing argument for -exec, meaning I am actually stuck. Any input?

find /media/DRIVE-N-GO/Backup\ Wiebe/ -type f -name *.jpg -exec cp {} /media/Elements/jpgs/ \
find /media/DRIVE-N-GO/Backup\ Wiebe/ -type f -name "*.jpg" -exec cp "{}" /media/Elements/jpgs/ \;

You were missing a ;. The quotes are around the search term for preventing bash from expanding the asterisk The quotes around the parameter of cp are when some files with spaces in the name are hit - because then cp would fail

  • Hahahahaha..... just wow. Makes me feel like a complete idiot. Thanks so much people! – Ruben Mar 14 '14 at 13:03
  • 2
    Also missing quotes around *.jpg. It works fine without escaping the * ... until run it while standing in a directory that happens to have files ending in .jpg. – geirha Mar 14 '14 at 13:13

You have to finish the command with an escaped semicolon:

... -exec cp {} directory \;

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.