find: Single File
1
1 3.3.1 Single File
1 -----------------
1
1 Here is how to run a command on one file at a time.
1
1 -- Action: -execdir command ;
1 Execute COMMAND; true if COMMAND returns zero. 'find' takes all
1 arguments after '-execdir' to be part of the command until an
1 argument consisting of ';' is reached. It replaces the string '{}'
1 by the current file name being processed everywhere it occurs in
1 the command. Both of these constructions need to be escaped (with
1 a '\') or quoted to protect them from expansion by the shell. The
1 command is executed in the directory which 'find' was searching at
1 the time the action was executed (that is, {} will expand to a file
1 in the local directory).
1
1 For example, to compare each C header file in or below the current
1 directory with the file '/tmp/master':
1
1 find . -name '*.h' -execdir diff -u '{}' /tmp/master ';'
1
1 If you use '-execdir', you must ensure that the '$PATH' variable
1 contains only absolute directory names. Having an empty element in
1 '$PATH' or explicitly including '.' (or any other non-absolute name) is
1 insecure. GNU find will refuse to run if you use '-execdir' and it
1 thinks your '$PATH' setting is insecure. For example:
1
1 '/bin:/usr/bin:'
1 Insecure; empty path element (at the end)
1 ':/bin:/usr/bin:/usr/local/bin'
1 Insecure; empty path element (at the start)
1 '/bin:/usr/bin::/usr/local/bin'
1 Insecure; empty path element (two colons in a row)
1 '/bin:/usr/bin:.:/usr/local/bin'
1 Insecure; '.' is a path element ('.' is not an absolute file name)
1 '/bin:/usr/bin:sbin:/usr/local/bin'
1 Insecure; 'sbin' is not an absolute file name
1 '/bin:/usr/bin:/sbin:/usr/local/bin'
1 Secure (if you control the contents of those directories and any
1 access to them)
1
1 Another similar option, '-exec' is supported, but is less secure.
1 ⇒Security Considerations, for a discussion of the security
1 problems surrounding '-exec'.
1
1 -- Action: -exec command ;
1 This insecure variant of the '-execdir' action is specified by
1 POSIX. Like '-execdir command ;' it is true if zero is returned by
1 COMMAND. The main difference is that the command is executed in
1 the directory from which 'find' was invoked, meaning that '{}' is
1 expanded to a relative path starting with the name of one of the
1 starting directories, rather than just the basename of the matched
1 file.
1
1 While some implementations of 'find' replace the '{}' only where it
1 appears on its own in an argument, GNU 'find' replaces '{}'
1 wherever it appears.
1