Find is a command that uses a higher frequency. It is often used in a system-specific directory to find files that have some kind of feature.
Format of the Find command: Find [-path ...]-options [-print-exec-ok]
Path: The directory path to find.
~ Represents the $home directory
. Represents the current directory
/Represents the root directory
Print: Indicates that the result is output to standard output.
EXEC: Executes the shell command given by the parameter to the matching file.
The form is command {} \;, note {} and \; There is a space between
OK: As with the EXEC function,
The difference is that a prompt is given before the command is executed to let the user confirm whether the
Options are commonly used with the following option:
-name: Search by name
-perm: Install permissions Lookup
-prune: No longer found under the currently specified directory
-user: File owner to find
-group: File belongs to group to find
-nogroup: Finding files with no valid owning group
-nouser: Finding files with no valid owner
-type: Search by file type
Here are some simple examples to illustrate the general use of the next find:
1. Search by name
In the current directory and subdirectories, find the TXT file at the beginning of the capital letter
$ find. -name ' [A-z]*.txt '-print
In/etc and its subdirectories, look for files at the beginning of host
$ Find/etc-name ' host* '-print
In the $home directory and its subdirectories, find all Files
$ find ~-name ' * '-print
In the current directory and subdirectories, find the TXT file that is not the beginning of the out
$ find. -name "out*"-prune-o-name "*.txt"-print
2. Search by directory
Search for txt files in subdirectories other than AA in the current directory
$ find. -path "./aa"-prune-o-name "*.txt"-print
Find txt files in the current directory and subdirectories other than AA and BB
$ find. \ (-path "./aa"-o-path "./bb" \)-prune-o-name "*.txt"-print
In the current directory, no longer subdirectories, find txt files
$ find. ! -name "."-type d-prune-o-type f-name "*.txt"-print
3. Search by permissions
In the current directory and subdirectories, look for the master with read and write execution, and other files with reading Execute permission
$ find. -perm 755-print
4. Search by Type
In the current directory and subdirectories, locate the symbolic link file
$ find. -type L-print
5. According to the owner and genus Group
Find files that belong to www
$ find/-user Www-type F-print
Find files that belong to the main deleted
$ find/-nouser-type F-print
Find files belonging to the group MySQL
$ find/-group Mysql-type F-print
Find files deleted by user group
$ find/-nogroup-type F-print
6. Search by Time
Find files that have been changed in 2 days
$ find. -mtime-2-type F-print
Find files that have been changed 2 days ago
$ find. -mtime +2-type F-print
Find files that are accessed in a day
$ find. -atime-1-type F-print
Find files that were accessed a day ago
$ find. -atime +1-type F-print
Find files that are changed in the day
$ find. -ctime-1-type F-print
Find a day ago state changed file
$ find. -ctime +1-type F-print
Find files with status changed 10 minutes ago
$ find. -cmin +10-type F-print
7, according to the old and new documents
Find a new file than Aa.txt
$ find. -newer "Aa.txt"-type f-print
Look for older files than Aa.txt
$ find. ! -newer "Aa.txt"-type f-print
Find newer than aa.txt, older than bb.txt files
$ find. -newer ' Aa.txt '! -newer ' Bb.txt '-type f-print
8. Search by size
Find files that are over 1M
$ find/-size +1m-type F-print
Find files that are equal to 6 bytes
$ find. -size 6c-print
Find files that are less than 32k
$ find. -size-32k-print
9. Execution of Orders
Find Del.txt and delete, prompt confirmation before deleting
$ find. -name ' Del.txt '-ok rm {} \;
Find Aa.txt and back up as Aa.txt.bak
$ find. -name ' Aa.txt '-exec cp {} {}.bak \;
Summary of Find command usage under Linux