Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using -exec option with Find command in Bash

Tags:

linux

find

exec

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/

like image 561
Hollis Avatar asked Dec 29 '22 07:12

Hollis


2 Answers

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

like image 137
Karl Bielefeldt Avatar answered Jan 15 '23 07:01

Karl Bielefeldt


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 \;
like image 24
dogbane Avatar answered Jan 15 '23 07:01

dogbane