File Lookup: Locate, find
Non-real-time lookup (Database lookup): Locate
Real-time Find: Find
Locate
Working mode:
(1) dependent on pre-built indexes
(2) The index is built automatically when the system is idle (recurring tasks)
(3) Manually updating the database (UpdateDB)
Note: The index build process needs to traverse the entire root filesystem, consuming resources very
Working characteristics:
(1) Fast search speed
(2) Fuzzy search
(3) Non-real-time search
Command format:
Locate KEYWORD
Find
Real-time Find tool to complete file lookups by traversing a file system under a specified path
Working characteristics
(1) Search speed slightly slower
(2) Exact search
(3) Real-time search
Grammar:
Find [OPTION] ... [Find Path] [Search Criteria] [Handling Action]
Find path: Specify a specific target path; defaults to the current directory
Search criteria: Specifies the criteria for finding criteria, such as file name, size, type, permissions, etc., by default to find all files under the specified path
Handling actions: What to do with the eligible files; Default output to screen
Search criteria:
Search by file name:
-name "file name": Support for using Glob
*, ?, [], [^]
-iname "file name": Letter case insensitive
-regex "pattern": matches the entire file path string with pattern, not just the file name
According to the genus, the genus Group looks for:
-user USERNAME: Find files that belong to the specified user
-group GRPNAME: Finding files belonging to groups of specified groups
-uid UserID: Find the file that belongs to the specified UID number
-gid GroupID: Finding files with a specified GID number for the genus Group
-nouser: Finding files that are not owned by the master
-nogroup: Finding files that are not owned by a group
Find by File type:
-type Type:
F: Normal file
D: Catalog file
L: Symbolic Link file
S: Socket file
B: Block device files
C: Character device file
P: Pipeline File
Combination conditions:
With:-A
Or:-O
Non:-not,!
! A-a! B =! (A-o B)
! A-o! B =! (A-a B)
Depending on the file size, look for:
-size [+|-] #UNIT
Common units: K, M, G
#UNIT: (#-1, #)
-#UNIT: [0,#-1]
+ #UNIT: (#,oo)
Based on time stamp:
In "Days" as the unit
-atime [+|-]#,
#: [#,#+1]
+#: [#+1,oo]
-#: [0,#]
-mtime
-ctime
In "Minutes" units:
-amin
-mmin
-cmin
Search by permissions:
-perm [/|-]mode
MODE: Exact permission match
/mode: The permission of any class of (U,g,o) object can be as long as one match
-mode: Each class of object must have both the permission criteria specified for it
Handling actions:
-print: Default processing action, display to screen
-ls: Similar to performing a "ls-l" command on a found file
-delete: Delete the found file
-fls/path/to/somefile: Long format information for all files found is saved to the specified file
-ok COMMAND {} \; : Executes commands specified by command on each file found
Users are interactively asked to confirm the command before each file executes
-exec COMMAND {} \; : Executes commands specified by command on each file found
{}: Used to reference the found file name itself
Note:find passes the found file to the command specified later, finds all eligible files once passed to the following command
Some commands cannot accept too many arguments, at which point the command execution may fail, another way to circumvent the problem
Find | Xargs COMMAND
This article is from the "Ricky Technology Blog" blog, make sure to keep this source http://r1cky.blog.51cto.com/10646564/1773851
Linux file Lookup