implies -nowarn) by default, because POSIX requires that apart from the output for -ok, all messages printed on stderr are diagnostics and must
result in a non‐zero exit status.
When POSIXLY_CORRECT is not set, -perm +zzz is treated just like -perm /zzz if +zzz is not a valid symbolic mode. When POSIXLY_CORRECT is set, such constructs are treated as an error.
When POSIXLY_CORRECT is set, the response to the prompt made by the -ok action is interpreted according to the system’s message catalogue, as opposed to according to find’s own message translations.
TZ Affects the time zone used for some of the time‐related format directives of -printf and -fprintf.
EXAMPLES
Simple ‘find|xargs‘ approach
• Find files named core in or below the directory /tmp and delete them.
$ find /tmp -name core -type f -print | xargs /bin/rm -f
Note that this will work incorrectly if there are any filenames containing newlines, single or double quotes, or spaces.
Safer ‘find ‐print0 | xargs ‐0‘ approach
• Find files named core in or below the directory /tmp and delete them, processing filenames in such a way that file or directory names containing single or double quotes, spaces or newlines are correctly han‐
dled.
$ find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
The -name test comes before the -type test in order to avoid having to call stat(2) on every file.
Note that there is still a race between the time find traverses the hierarchy printing the matching filenames, and the time the process executed by xargs works with that file.
Processing arbitrary starting points
• Given that another program proggy pre‐filters and creates a huge NUL‐separated list of files, process those as starting points, and find all regular, empty files among them:
$ proggy | find -files0-from - -maxdepth 0 -type f -empty
The use of ‘-files0-from -‘ means to read the names of the starting points from standard input, i.e., from the pipe; and -maxdepth 0 ensures that only explicitly those entries are examined without recursing
into directories (in the case one of the starting points is one).
Executing a command for each file
• Run file on every file in or below the current directory.
$ find . -type f -exec file '{}' \;
Notice that the braces are enclosed in single quote marks to protect them from interpretation as shell script punctuation. The semicolon is similarly protected by the use of a backslash, though single quotes
could have been used in that case also.
In many cases, one might prefer the ‘-exec ... +‘ or better the ‘-execdir ... +‘ syntax for performance and security reasons.
Traversing the filesystem just once ‐ for 2 different actions
• Traverse the filesystem just once, listing set‐user‐ID files and directories into /root/suid.txt and large files into /root/big.txt.
$ find / \
\( -perm -4000 -fprintf /root/suid.txt '%#m %u %p\n' \) , \
\( -size +100M -fprintf /root/big.txt '%-10s %p\n' \)
This example uses the line‐continuation character '\' on the first two lines to instruct the shell to continue reading the command on the next line.
Searching files by age
• Search for files in your home directory which have been modified in the last twenty‐four hours.
$ find $HOME -mtime 0
This command works this way because the time since each file was last modified is divided by 24 hours and any remainder is discarded. That means that to match -mtime 0, a file will have to have a modification
in the past which is less than 24 hours ago.
Searching files by permissions
• Search