FIND
Search a folder hierarchy for filename(s) that meet a desired criteria: Name, Size, File Type etc.
SYNTAX
find [path…] [options] [tests] [actions]
find searches the directory tree starting at the given pathname (or pathnames if several are given)
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. (see Operators)
Conditions may be grouped by enclosing them in ( ) (escaped parentheses), negated with !, given as alternatives by separating them with -o, or repeated (adding restrictions to the match; usually only for -name, -type, or -perm). Note that "modification" refers to editing of a file&qt;&qt;s contents, whereas "change" means a modification, or permission or ownership changes. In other words, -ctime is more inclusive than -atime or -mtime.
The first argument that begins with a – or ( or ) or , or ! is taken to be the beginning of the expression; any arguments before this are paths to search, and any arguments after it are the rest of the expression.
If no paths are given, the current directory is used. If no action is given, &qt;-print&qt;&qt; is used.
find exits with status 0 if all files are processed successfully, greater than 0 if errors occur.
Examples
List all filenames ending in .mp3, searching in the current folder and all subfolders:
find . -name "*.mp3"
List all filenames ending in .mp3, searching in the music folder and subfolders:
find ./music -name "*.mp3"
List files with the exact name: Sales_document.doc in ./work and subfolders:
find ./work -name Sales_document.doc
List all files that belong to the user Simon:
find . -user Simon
List all the directory and sub-directory names:
find . -type d
List all files in those sub-directories (but not the directory names)
find . -type f
List all the file links:
find . -type l
List all files (and subdirectories) in your home directory:
find $HOME
Find files that are over a gigabyte in size:
find ~/Movies -size +1024M
Find files have been modified within the last day:
find ~/Movies -mtime -1
Find files have been modified within the last 30 minutes:
find ~/Movies -mmin -30
Find .doc files that also start with &qt;&qt;questionnaire&qt;&qt; (AND)
find . -name &qt;&qt;*.doc&qt;&qt; -name questionnaire*
List all files beginning with &qt;&qt;memo&qt;&qt; and owned by Simon (AND)
find . -name &qt;&qt;memo*&qt;&qt; -user Simon
Find .doc files that do NOT start with &qt;&qt;Accounts&qt;&qt; (NOT)
find . -name &qt;&qt;*.doc&qt;&qt; ! -name Accounts*
Search for files which have read and write permission for their owner,
and group, but which the rest of the world can read but not write to.
find . -perm 664
Files which meet these criteria but have other permissions bits set
(for example if someone can execute the file) will not be matched.
Search for files which have read and write permission for their owner,
and group, but which the rest of the world can read but not write to,
without regard to the presence of any extra permission bits
(for example the executable bit).
find . -perm -664
This will match a file which has mode 0777, for example.
Search for files which are writeable by somebody (their owner, or their group, or anybody else).
find . -perm +222
or
find . -perm +g+w,o+w
or
find . -perm +g=w,o=w
All three of these commands do the same thing, but the first one uses
the octal representation of the file mode, and the others use the symbolic form.
The files don&qt;&qt;t have to be writeable by both the owner and group to be matched; either will do.
Search for files which are writeable by both their owner and their group:
find . -perm -022
or
find . -perm -g+w,o+w