find
Search for files in a directory hierarchy
Overview
The find command searches the directory tree rooted at each given starting-point by evaluating the given expression from left to right, according to the rules of precedence, until the outcome is known (the left hand side is false for and operations, true for or), at which point find moves on to the next file name.
Syntax
find [path...] [expression]Common Options
-name patternBase of file name (the path with the leading directories removed) matches shell pattern pattern.
-iname patternLike -name, but the match is case insensitive.
-type cFile is of type c: f (regular file), d (directory), l (symbolic link), c (character special), b (block special), p (FIFO), s (socket).
-user unameFile is owned by user uname (numeric user ID allowed).
-group gnameFile belongs to group gname (numeric group ID allowed).
-perm modeFile`s permission bits are exactly mode (octal or symbolic).
-mtime nFile`s data was last modified n*24 hours ago.
-atime nFile`s data was last accessed n*24 hours ago.
-ctime nFile`s status was last changed n*24 hours ago.
-size n[cwbkMG]File uses n units of space (c for bytes, w for two-byte words, b for 512-byte blocks (default), k for Kilobytes, M for Megabytes, G for Gigabytes).
-emptyFile is empty and is either a regular file or a directory.
-deleteDelete files; true if removal succeeded. If the removal failed, an error message is issued.
-exec command {} \;Execute command; true if 0 status is returned. All following arguments to find are taken to be arguments to the command until an argument consisting of ‘;’ is encountered. The string ‘{}’ is replaced by the current file name being processed.
-maxdepth levelsDescend at most levels (a non-negative integer) levels of directories below the starting-points.
-mindepth levelsDo not apply any tests or actions at levels less than levels (a non-negative integer).
Examples
Find all .txt files in the current directory and its subdirectories.
Find all files owned by user john in the /home directory.
Find .log files in /var/log modified more than 7 days ago.
Find and delete all empty directories in the current path.
Find all .tmp files and remove them.
Find all executable files in /usr/bin.