4

I am trying to use the -exec option with the find command to find specific files in my massive panoramas directory and move them to a specified location. The command I am using below passes an error argument not found for -exec. Can somebody point out my error in parsing the command? Or would I have to create a pipe of some sorts instead?

$ find -name ~/path_to_directory_of_photos/specific_photo_names* -exec mv {} ~/path_to_new_directory/

2
  • 1
    Maybe move this over to serverfault? Commented Sep 24, 2010 at 19:54
  • I voted to migrate to SuperUser.Com, but it actually would be more appropriate on Unix.StackExchange.Com. Commented Sep 24, 2010 at 21:01

3 Answers 3

7

You need to terminate your exec'ed command with an escaped semicolon (\;).

Sign up to request clarification or add additional context in comments.

1 Comment

Ok thank you, missed a space at the end between ~/path_to_new_directory and \; that was tripping me up. Solved.
3

You should quote the name pattern otherwise the shell will expand any wildcards in it, before running find. You also need to have a semicolon (backslashed to avoid the shell interpreting it as a command separator) to indicate the end of the mv command.

The correct command would be:

find ~/path_to_directory_of_photos -name "specific_photo_names*" -exec mv {} ~/path_to_new_directory \;

Comments

1

I know this post is old, but here's my answer in case it helps anyone else. See the background from this post. If you end the command with + instead of \; you can run it much more efficiently. \; will cause "mv" to be executed once per file, while + will cause "mv" to be executed with the maximum number of arguments. E.g.

mv source1 destination/
mv source2 destination/
mv source3 destination/

vs.

mv source1 source2 source3 destination/

The latter is much more efficient. To use +, you should also use --target-directory. E.g.

find ~/path_to_directory_of_photos -name "specific_photo_names*" -exec mv --target-directory="~/path_to_new_directory" {} +

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.