First, File Search command classification
1.locate command
The command is non-real-time, fuzzy matching, the search is based on the system-wide file database, faster, you can define the policy to update the database, you can also use the UpdateDB command to manually generate or update the file database, the command is not used frequently.
2.find command
This command is real-time, exact lookup, traverse all the files in all directories to complete the lookup, slow, but support a large number of search criteria, is the most frequently used file Lookup command.
Use format for 3.find commands:
Find Find Path Lookup criteria finds a later processing action
Find path: Default to current directory
Lookup criteria: Default to all files under the specified path
Find a future processing action: Print to screen by default
Second, find the standard
-name ' FILENAME ' |
The command matches the file name exactly, and you can use the file name wildcard character *: Any character of any length ? : Any character with a length of 1 []: Any character in the specified range |
-iname ' FILENAME ' |
File name matching is case insensitive |
-regex PATTERN |
File name matching based on regular expressions |
-user USERNAME
|
Based on owner Lookup |
-group GROUPNAME
|
Find by array |
-uid UID
|
Find by UID
|
-gid GID |
Search by GID |
-nouser
|
Find files that are not owned by the master
|
-nogroup |
Finding files with no arrays |
-type
|
F: Normal file
|
D: Catalogue
|
C: Character device file
|
B: Block device files
|
L: Link File
|
P: Piping Equipment files
|
S: Socket file
|
-size
|
[+|-] #k: Find files in K units
|
[+|-] #M: Find files in M units |
[+|-] #G: Find a file in units of G |
-mtime [+ |-]#
|
Modify time, file last modified, Unit is day |
-ctime [+ |-]# |
Change time, the date the file was last changed, in days |
-atime [+ |-]# |
Access time, the date the file was last accessed, in days |
-mmin [+ |-]#
|
Ditto, unit is minutes |
-cmin [+ |-]# |
Ditto, unit is minutes |
-amin [+ |-]# |
Ditto, unit is minutes |
-perm MODE
|
Exact match |
-perm-mode |
Conditional only if file permissions are fully contained in this mode |
-perm/mode |
Any one match that satisfies the condition
|
Three, the combination of conditions
-A |
-and and Conditions |
-O |
-or or conditions |
-not |
Non- conditional |
Iv. Handling of actions
-Print |
Show |
-ls
|
Detailed display of information for each document |
-ok COMMAND {} \; |
User confirmation is required for each operation
|
-exec COMMAND {} \; |
No user confirmation required
|
Five, File search exercises
1. Find all files in the/var directory that are subordinate to the root and belong to the group Mail
Find/var-user root-a-group Mail
2. Find files that do not belong to Root,bin, or student in the/usr directory
Find/usr-not-user root-a-not-user bin-a-not-user Student
Or
Find/usr-not \ (-user root-o-user bin-o-user student\)
3. Find files that have been modified over the last week in the/etc directory and are not part of the root and Kdyzm users
Find/etc-mtime-7-a-not \ (-user root-o-user kdyzm \)
Or
Find/etc-mtime-7-a-not-user root-a-not-user Kdyzm
4. Find files on the current system that are not owned by the master or group and have been accessed in the last 1 days, and change their genus to root
Find/-mtime-1-a \ (-nouser-o-nogroup \)-exec chown root.root {} \;
5. Find files larger than 1M in the/etc directory and write their filenames to the/tmp/etc.largefiles file
Find/etc-size +1m >>/tmp/etc.largefiles
6. Find files with no write permission for all users in/etc directory, display their details
Find/etc-not-perm/222-ls
This article is from the "stolen A Plum blog" blog, please be sure to keep this source http://kdyzm.blog.51cto.com/8316029/1741454
"Linux Learning 013" File lookup