1. The following commands are equivalent:
find .
find . -print
They both write out the entire directory hierarchy from the
current directory.
2. The following command:
find / \( -name tmp -o -name '*.xx' \) -atime +7 -exec rm {} \;
removes all files named tmp
or ending in .xx
that have not
been accessed for seven or more 24-hour periods.
3. The following command:
find . -perm -o+w,+s
prints (-print
is assumed) the names of all files in or below
the current directory, with all of the file permission bits
S_ISUID, S_ISGID, and S_IWOTH set.
4. The following command:
find . -name SCCS -prune -o -print
recursively prints pathnames of all files in the current
directory and below, but skips directories named SCCS and
files in them.
5. The following command:
find . -print -name SCCS -prune
behaves as in the previous example, but prints the names of
the SCCS directories.
6. The following command is roughly equivalent to the -nt
extension to test:
if [ -n "$(find file1 -prune -newer file2)" ]; then
printf %s\\n "file1 is newer than file2"
fi
7. The descriptions of -atime
, -ctime
, and -mtime
use the
terminology n ``86400 second periods (days)''. For example, a
file accessed at 23:59 is selected by:
find . -atime -1 -print
at 00:01 the next day (less than 24 hours later, not more
than one day ago); the midnight boundary between days has no
effect on the 24-hour calculation.
8. The following command:
find . ! -name . -prune -name '*.old' -exec \
sh -c 'mv "$@" ../old/' sh {} +
performs the same task as:
mv ./*.old ./.old ./.*.old ../old/
while avoiding an ``Argument list too long'' error if there
are a large number of files ending with .old
and without
running mv if there are no such files (and avoiding ``No such
file or directory'' errors if ./.old
does not exist or no
files match ./*.old
or ./.*.old
).
The alternative:
find . ! -name . -prune -name '*.old' -exec mv {} ../old/ \;
is less efficient if there are many files to move because it
executes one mv command per file.
9. On systems configured to mount removable media on directories
under /media
, the following command searches the file
hierarchy for files larger than 100000 KB without searching
any mounted removable media:
find / -path /media -prune -o -size +200000 -print
10. Except for the root directory, and "//"
on implementations
where "//"
does not refer to the root directory, no pattern
given to -name
will match a <slash>, because trailing <slash>
characters are ignored when computing the basename of the
file under evaluation. Given two empty directories named foo
and bar
, the following command:
find foo/// bar/// -name foo -o -name 'bar?*'
prints only the line "foo///"
.