Next: , Up: Run Commands



3.3.1 Single File

Here is how to run a command on one file at a time.

— Action: -execdir command ;

Execute command; true if 0 status is returned. find takes all arguments after -exec to be part of the command until an argument consisting of ; is reached. It replaces the string {} by the current file name being processed everywhere it occurs in the command. Both of these constructions need to be escaped (with a \) or quoted to protect them from expansion by the shell. The command is executed in the directory in which find was run.

For example, to compare each C header file in the current directory with the file /tmp/master:

          find . -name '*.h' -execdir diff -u '{}' /tmp/master ';'
     

Another similar option, -exec is supported, but is less secure. See Security Considerations, for a discussion of the security problems surrounding -exec.

— Action: -exec command ;

This insecure variant of the -execdir action is specified by POSIX. The main difference is that the command is executed in the directory from which find was invoked, meaning that {} is expanded to a relative path starting with the name of one of the starting directories, rather than just the basename of the matched file.