Getting Started

Usage

find [starting-point...] [expression]

Example

find /usr/src -name '*.c' -size +100k -print

Options

   
-P NOT follow symbolic links
-L Follow symbolic links
-H Not follow symbolic links ,except while processing
the command line arguments
-depth Process each directory’s contents before itself
-maxdepth 0 … N
-mindepth 1 … N 1 means means process all files except
the starting-points
-mount Don’t descend directories on other filesystems
-xdev same as -mount

Test

   
-empty Empty file or directory
-executable executable and directories are searchable
-fstype type file system type, like xfs nfs
-iname pattern case insensitive
-inum n File has inode number n
-ipath pattern case insensitive
-links n File has n links
-path pattern find . -path “./sr*sc” matches
./src/misc

Time

   
+n for greater than n
-n for less than n
n for exactly n
-amin n File was last accessed n minutes ago
-anewer file File was last accessed more recently than
file was modified
-atime n File was last accessed n*24 hours ago
-cmin n File’s status was last changed n minutes ago
-cnewer file File’s status was last changed more recently
than file was modified
-ctime n File’s status was last changed n*24 hours ago
-mmin n last modified n minutes ago
-mtime n last modified n*24 hours ago
-used n File was last accessed n days after its status
was last changed
#file been modified WITHIN 5 minutes
find . -mmin -5  
#find most recently modified files
find -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2-

Size

-size n[cwbkMG] File uses n units of space, rounding up
b for 512-byte blocks
c for bytes
w for two-byte words
k for Kilobytes
M for Megabytes
G for Gigabytes
+ greater than
- less than

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)

Owner

   
-gid n Group ID is n
-group gname group name
-uid n File’s numeric user ID is n
-user uname File is owned by user uname

Mode bits

   
-perm mode exactly mode (octal or symbolic)
-perm 755
-perm -mode All of the permission bits mode are
set for the file-perm -g=w
-perm /mode Any of the permission bits mode are
set for the file
-readable readable
-writable Matches files which are writable

Operator

   
( expr ) Force precedence \(expr\)
! expr False
not expr False
expr1 expr2 AND
expr1 -o expr2 OR
expr1 , expr2 list

Actions

   
-delete delete file
-exec command '{}' \; Execute command
-prune for directory, do not descend into it
-print0 without newline

Example

find . -path ./src/emacs -prune -o -print
#Exclude directory ./src/emacs

Regular expression

   
-regextype type Changes the regular expression syntax
find -regextype help to list supported
* zero or more characters
? Matches any one character
[string] [a-z0-9] matches a lowercase letter, a number
\ Remove special character