Process files in directory before the directory itself.
-prune
do not descend the current directory; true. With -depth, false; no effect.
-maxdepth l
Descend at most levels of directories below the command line arguments. 0 i.e. only apply the tests and actions to the command line arguments.
-mindepth l
Do not apply any tests or actions at levels less than levels1 i.e. process all files except the command line arguments.
-follow
DEreference symbolic links. Implies -noleaf.
-noleaf
Needed when searching non-Unix filesystems, such as CD-ROM or MS-DOS
or AFS.
Each directory on a Unix filesystem has at least 2 hard links: its name and its . entry.
Its subdirectories each have a .. entry linked to that directory.
‑xdev ,
‑mount
Don't descend directories on other filesystems.
-daystart
Measure times from the beginning of today rather than from 24 hours ago.
(see -amin, -atime, -cmin, -ctime, -mmin, and -mtime)
-version
-help
tests
Numeric arguments can be specified as +n for greater than, -n for less than.
-name pattern
Filename matches pattern.
The metacharacters (*, ?, and []) do not match a . at the start of the base name.
(i.e. find ~ -name "*rc" does not find .bashrc).
To ignore a directory and the files under it, use -prune:
find . -path ./src/emacs -prune -o -print
/usr/bin/find . -name 2011-08-\*
-iname pattern
case insensitive.
ex: "fo*" or "F??" matches Foo, FOO, foo, fOo, etc.
-regex pattern
File name matches regular expression pattern.
This is a match on the whole path, not a search.
For example, to match a file named fubar3 use the regular expression bar. or b.*3 but not b.*r3
-iregex pattern
case insensitive.
Time related options
Numeric arguments of time are specified as
+n older than
-n for newer than
omitting the sign indicates equal to ( and must match exactly )
minutes since
hours is
minutes.
Find files modified a long time ago and format the output of find's ls to look more like ls -l
Measure times from the beginning of today rather than from 24 hours ago.
Data Modified
-mmin ±mmm
data was last modifiedmmm minutes ago.
Use -mmin -10 for less than 10 minutes ago (i.e. after 10 minutes ago, -30 shows more files.
-mtime ±ddd
ddd*24 hours ago (days ago)†.
Remove files (and direcrories) not modified in the last 2 years
find . -not -mtime -730 -exec rm -r {} \;
-newer file
more recently than file.
affected by -follow only if -follow comes before -newer on the command line.
Example:
Find, beginning in the parent/parent directory ,
only files, newer than DBtables.cgi and
do an ls supressing the group and cutting off the mode-flags and the owner.
find ../.. -type f -newer DBtables.cgi -exec /bin/ls -lg {} \; |cut -c21-
Accessed (Not all systems update the time files are accessed see mount -o noatime )
-amin ±mmm
accessed exactly mmm minutes ago. -amin -5 for files accessed in last 5 mintes. +4464 lists files not accesses in last 31 days.
-anewer file
more recently than file was modified.
affected by -follow only if -follow comes before -anewer on the command line.
Example,
starting at the current directory, find files, larger than 6MB created recently
(i.e. within last 8 hours) ( if -type f is omitted ls will follow directories)
an cut off the mode flags and owner.
Numeric arguments are specified as +n for greater than, -n for less than, ommitting the sign indicates equal to.
-size ±nc†
more|less than nkilobytes,
nbblocks(default),
ncharacters , or 2-byte words nw.
-empty
Well, if the file is empty
-pathpattern
name matches shell pattern pattern.
The metacharacters do not treat / or . specially; so, for example, find . -path ./sr*sc
will output an entry for a directory called ./src/misc .
To ignore a whole directory tree, use -prune rather
than checking every file in the tree.
For example, to skip the directory src/emacs and all files and directories under it,
and output the names of the other files found: find . -path ./src/emacs -prune -o -print
-ipathpattern
match is case insensitive.
-perm mode
File's permission bits are exactly mode (octal or symbolic).
Symbolic modes use mode 0 as a point of departure.
-perm -mode
All of the permission bits mode are set for the file.
-perm +mode
Any ...
-false
-true
-fstype type
filesystem of type type, including ufs, 4.2, 4.3, nfs, tmp, mfs, S51K, S52K.
Use -printf with the %F directive to see the types of your filesystems.
-type t
block (buffered) special, character (unbuffered) special,
directory, named pipe (FIFO),
regular file,
symbolic link, socket , door (Solaris)
-xtype t
For symbolic links:
if -follow has not been given, true if the file is
a link to a file of type t;
if -follow has been given, true if t is l.
In other words, for symbolic links, -xtype checks the
type of the file that -type does not check.
-uidn
owned by user n.
-useruname
owned by user uname (numeric user ID allowed).
-nouser
owner no longer exists, i.e. No /etc/passwd record
-gid n
numeric group ID is n.
-group gname
belongs to group gname (numeric group ID allowed).
-nogroup
group no longer exists.
-inum n
has inode number n.
-links n
has n links.
-lname pattern
symbolic link whose contents match pattern .
The metacharacters do not treat / or . specially.
-print
output the full file name followed by a newline.
-print0
filename followed by a null .
Useful if file name might contain \n or spaces or other special characters .
Useful with xargs
Specifiy Field widths and precisions.
-fprintofile output the full file name to ofile.
Does not add a newline at the end of the string (so use \n at the end of the specs).
Interprets \ escapes and % as directives.
-fprint0 ofile
-printf"specs" output specs
-fprintf ofile "specs"
escapes:
\a alert bell \b Backspace (repositions cursor over previous char) \c Stop and flush the output \f Form feed \n Newline \r Carriage return \t Horizontal tab \v Vertical tab \\ backslash %% percent sign \nnn The character whose ASCII code is nnn (octal)
A \ followed by any other character is treated as an ordinary character, both are output
directives:
%a access time Sun Jun 12 13:36:18 2005
%Ak format specified by k
either fc† or a directive for the C strftime function.
"%AT"
13:36:18
%kvsize in 1K , %b in 512-byte blocks , %s in bytes. %d depth in the directory tree; 0 i.e. the file is a command line argument. %h Leading directories of file's name (all but the last element). %f name with any leading directories removed (only the last element). %p name. %P File's name with the name of the command line argument under which it was found removed. %H Command line argument under which file was found.
%F Type of the filesystem the file is on; this value can be used for -fstype. %g group name, or numeric group ID if the group has no name. %G numeric group ID. %i inode number %l Object of symbolic link (empty string if not a symbolic link). %m permission bits (in octal). %n Number of hard links to file. %u owner, or numeric user ID if the user has no name. %U numeric user ID.
A % character followed by any other character is discarded (the other character is output).
OPERATORS
Listed in order of decreasing precedence:
Default operator is -and .
\†( expr \†)
\†! exprfalse if expr is true. -not
expr1 -and expr2 expr2
is not evaluated if expr1is false. expr1 -a expr2 expr1expr2 And (implied) expr1 , expr2 List; both expr1 and expr2 are always evaluated.
expr1 -o expr2 Or;
expr2 is not evaluated if expr1 is true. expr1 -or expr2
The value of expr1 is discarded.
The value of the list is the value of expr2.