Find command Summary
Real-time
Precision
Supports multiple search criteria
Traversing all the files in the specified directory to complete the search, the speed is relatively slow;
Find path search standard search for future processing operations
Search Path: the current directory by default
Search criteria: All files in the specified path by default
Processing operation: Display by default
Matching criteria
-Name 'filename': exact match of file names
Wildcard File Name:
*: Any character of any length
?
[]
-Iname 'filename': the file name is case insensitive when matching.
Instance:
Find./-name "*. conf"
Find./-iname "ACC. c" ignore case sensitivity!
Find.-perm 777
++ ++
-User USERNAME: search by owner
-Group GROUPNAME: search by group
-Uid UID: search by UID
-Gid GID: search by GID
-Nouser: Search for files with no owner
-Nogroup: Search for files without groups
Instance:
1. Find all the files whose owner is root and whose group is mail in the/var directory;
Find/var-user root-group mail
2. Search for files that do not belong to root, bin, or student under the/usr directory;
Find/usr-not-user root-a-not-user bin-a-not-user student
Find/usr-not \ (-user root-o-user bin-o-user student \)
++ ++
-Type
F: Common File
D: Directory
C: character device
B: Block devices
L: soft connection file
P: MPS queue File
S: set of characters
Instance:
Find/etc-type f
Find/etc-type d
Find ./! -Type d # search all types of files except directories in the current directory
++ ++
-Size [+ |-]
Indicates the file size. + indicates that the file size is greater than a certain number.-indicates that the file size is smaller than a certain number. c indicates that the Unit is byte. You can change c to k, M, G.
Instance:
Find./-size 0-exec rm {}\;
Find./-size 0 | xargs rm-f
Find.-size + 000000c # search for files with a length greater than 1 MB in the current directory
Find/home/apache-size 100c # find a file with a length of exactly 100 bytes in the/home/apache directory
Find.-size + 10 # search for files with more than 10 blocks in the current directory (one block equals 512 bytes)
++ ++
File status judgment
-Mtime: the content of the specified time file has been modified.
-Ctime: the permission of the specified time file has been modified.
-Atime: the specified time file has been read.
1. Find the document that has been modified three days ago.
Find/var/log/-mtime + 3-type f-print
2. Find the modified document within three days.
Find/var/log/-mtime-3-type f-print
3. Find the modified document in the last day.
Find/var/log/-mtime 3-type f-print
Or write as follows:
Find/var/log/-mtime + 2-mtime-4-type f-print
Note:
Access amin, modify mmin, and change the File status to cmin
Use amin, mmin, and cmin in minutes, and use atime, mtime, and ctime in days.
Find/logs-type f-mtime + 5-exec rm {}\; # find the files whose change time is earlier than 5 days in the/logs directory and delete them
Find/-mtime-5-print # find the file whose modification time is within 5 days in the system root directory
++ ++
-Mount: when searching for a file, it does not span the mount point of the file system. This is restricted to the current file system!
If this is not enough, we will not mention the instance!
++ ++
-Prune
Find/apps-path "/apps/bin"-prune-o-print # search for files in the/apps directory, but do not want to search for files in the/apps/bin directory. When using this command, either absolute path is preferred for each directory or corresponding to each directory, such as: find test/-path ". /test/a "-prune-o-print is incorrect.
-Depth: when searching for a file, first find the file in the current directory and then find it in its subdirectory.
-Maxdepth:
Find.-maxdepth 1-name fred # search in the current directory
Find.-maxdepth 2-name fred # search for the directory at the next level in the current directory
Find-mindepth 3-maxdepth 5-name passwd
[Root @ fb13/] # find.-maxdepth 3-name test
./B/test
./Usr/bin/test
./A/test
Find/project-maxdepth 2 \ (-path "/project/exapi/log"-o-path "/project/exapi/backup "\) -prune-o-print | grep "/project/exapi/" | xargs tar zcf/backup/exapi _ 'date when using f'.tar.gz
++ ++
Hybrid search:-a-o-not
Find/tmp-size + 0000000c-a-mtime + 2
Find/-user andy-o-user jack
Find/tmp-not-user zjqiu