find [path...] [expression]

2009 Mar 01


find recursively search each directory in path evaluating the expression for every file until the outcome is known (i.e. is true or false). The expression with the first argument that begins with '-', '(', ')', ',', or '!'. If no paths are given, the current directory is used. If no expression is given, then '-print' is used. find exits with status 0 if all files are processed successfully, greater than 0 if errors occur. The expression is made up of:


options
-daystart Measure times (for -amin, -atime, -cmin, -mmin, -mtime) from the beginning of today rather than from 24 hours ago
-depth Process each directpry's contents before the directory itself
-follow Derereference symbolic links. Implies -noleaf
-help Show command line usage
-maxdepth levels Descend at most levels of directories below command line arguments
-mindepth levels Do not apply any tests or actions at levels less than levels
-mount
-xdev
Do not descend directories on other filesystems
-noleaf Do not optimize by assuming that directories contain 2 fewer subdirectories than their hard link count. Needed for CD-ROM and MSDOS filessystems or AFS volume mount points. Only applies when limiting to directories and ignoring files.
-version Print find version and exit

Numeric arguments can be specified as:
+n : for greater than n
-n : for less than n
 n : for exactly n
tests
-amin n file was last accessed n minutes ago
-anewer file File was last accessed more recently than file was modified. -anewer is affected by -follow only if -follow comes before -anewer on cmnd line.
-atime n File was last accessed n*24 hours ago
-cmin n File's status was last changed n minutes ago
-cnewer file File status was last changed more recently than file was modified. -cnewer is affected by -follow only if -follow comes before -anewer on cmnd line.
-ctime n File's status was last changed n*24 hours ago
-empty File is empty and is either a regular file or a directory
-false Always false
-fstype type File is on a filesystem of type, one of: ufs, 4.2, 4.3, nfs, tmp, mfs, S51K, S52K. Use -preintf %F directive to see types on your system.
-gid n File's numeric group ID is n.
-group gname File belongs to group name gname.
-iname pattern Like -name, but match is case insensitive.
-inum n File has inode number n.
-ipath pattern Like -path, but match is case insensitive.
-iregex pattern Like -regex, but match is case insensitive.
-links n File has n links.
-mmin n File was modified n minutes ago.
-mtime n File was modified n*24 hours ago.
-name pattern Base of file name (path will leading directories removed) matches shell pattern.
-newer file File was modified more recently than file. Affected by -follow only if -follow comes before -newer on cmnd line.
-nouser No user corresponds to file's numeric user ID.
-nogroup No group corresponds to file's numeric group ID.
-path pattern File name matches shell pattern. The metacharacters do not treat '/' or '.' as special. To ignore a whole directory tree use -prune, e.g. to skip subtree srec/emacs do:
   find . -path '.src/emacs' -prune -o -print
-prem mode File's permissions are exactly mode (octal or symbolic).
-prem -mode All of the permission bits mode are set for the file.
-regex pattern File name (whole path) matches patern.
-size n[bckw] File uses n units of space. The units are 512-byte blocks by default or bytes if b or c, 2-byte words if w, kilobytes if k - follows n. Does not count blocks in sparse files not allocated.
-true Always true.
-type c
c type
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link
s socket
D door (Solaris)
-uid n File's numeric user ID is n.
-used n File was last accessed n days after its status was last changed.
-user uname File is owned by user uname (numeric allowed).
-xtype c Same as -type unless file is a symbolic link. If a symbolic link then if -follow not given then true if file linked to is of type c.

actions
-exec command ; Execute command ; true is status 0 returned. All following arguments to find are taken to be arguments to the command until the ;. The string '{}' is replaced by the current file name being processed everywhere it occues in the arguments to the command. Might need to be escaped with \ or quoted to protect them from shell.
-fls file True; like -ls but write to file like -fprint.
-fprint file True; print the full file name into file (can be /dev/stdout or /dev/sterr).
-fprint0 file True; print0 but write to file like -fprint.
-fprint file format True; like printf but write to file like -fprint.
-ls True; list current file in its 'ls -dils' format on stdout. Block counts are of 1K blocks unless the environment variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
-ok command ; Like -exec but ask the user first; if the response does not start with 'y' or 'Y, do not run the command, and return false.
-print True; print the full file name to stdout followed by a newline.
-print0 True; print the full file name to stdout followed by null character.
-printf format True; print format to stdout, interpreting '\' esacpes and '%' directives. Field widths and precisions can be specified as with the printf C function. No specific end of line character is output. The escapes and directives are:
\aalarm bell
\bbackspace
\cstop printing from this format
and flush the output
\fformfeed
\nnewline
\rcarriage return
\thorizontal tab
\vvertical tab
\\literal '\'
NNNcharacter of specified octal code
\.any other character after \ is printed
as \ followed by that character
%%literal '%'
%aFile's last access time - as by ctime()
%AkFile's last access time - in format specified by k which is either '@' or a directive of C lib strftime() :
Time fields
@ seconds since 1 Jan 1970 GMT
H Hour (00..23)
k Hour ( 0..23)
I Hour (00..12)
l Hour ( 0..12)
M Minute (00..59)
p locale's AM or PM
r Time (hh:mm:ss [AP]M)
S Second (00..61)
T Time, 24-hour (hh:mm:ss)
X Locale's time, (H:M:S)
Z Time zone, (e.g. EDT or blank if unknown)
Date fields
a Locale's abreviated weekday (Sun..Sat)
A Locale's full weekday (Sunday..Saturday)
b Locale's abreviated month (Jan..Dec)
B Locale's full month (January..December)
c Locale's date and time
d Day of month (01..31)
D Date (mm/dd/yy)
h Same as b
j Day of year (001..366)
m Month year (01..12)
U Week number, Sunday is first day of week (00..53)
w Day of week, Sunday is first (0..6)
W Week number, Monday is first day of week (00..53)
x Locale's data representation (mm/dd/yy)
y Last two digits of year (00..99)
x Year (1970..)
%bFile's size in 512-byte blocks (rounded up)
%cFile's last status change, in ctime() format.
%CkFile's last status change, in %A format.
%dFile's depth in directory tree (0..).
%fFile's name without path.
%FFile's filesystem type, see -fstype.
%gFile's group name, or numeric ID if none.
%GFile's group numeric ID.
%hLeading directories of file name.
%HCommand line path arg file found under.
%iFile's inode number (decimal).
%kFile's size in kb.
%lSymbolic link (emoty if none).
%mFile's permision bits (in octal).
%nNumber of hard links to file.
%pFile's name with command line arg.
%sFile's size in bytes.
%tFile's last modification time, in ctime() format.
%TkFile's last modification time, in %Ak format.
%uFile's user name, or numeric ID if none.
%UFile's user numeric ID.
%_Any other char, '_', is just , that character '_'.
-prune If -depth is not given then: true; do not descend current directory.
If -depth is given then: false; no effect.

operators (in decreasing precedence)
( expr ) force precedence
! expr not expr
not expr same as ! expr
expr1 expr2 expr1 AND expr2 (implied)
expr1 -a expr2 expr1 AND expr2
expr1 -and expr2 expr1 AND expr2
expr1 -o expr2 expr1 OR expr2
expr1 -or expr2 expr1 OR expr2
expr1 , expr2 list; both expr1 and expr2 are always evaluated.
The value of expr2 is the value of the list.

2005-2009