Locate
Non-real-time, Fuzzy Lookup, lookup based on the system-wide file database.
UpdateDB: Manually generating a file database
Advantages: Fast Speed
Find
Real-time search, accurate search.
Grammar:
Find [Find path] [find standard] [processing action]
Find path: Default to current directory
Lookup criteria: Default to all files under the specified path
Handling actions: Default to show
options [Find criteria]:
-name ' filename ': Exact Match of file name
FileName wildcard *,? 、[]
-iname ' filename ': Matching file names is case insensitive
-regex PATTERN: Finding based on regular expressions
Find based on file properties
-user USERNAME: Based on owner Lookup
-group GROUPNAME: Search by Genus Group
-uid UID: Search by UID
-gid GID: Search by GID
-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: Search by file type
F: Normal file
D: Catalogue
S: Socket file
C: Character device
B: Block device
L: Link File
P: Piping Equipment
Find by File size
-size: Search by File size
[+|-] #k: Find files larger than #k or less than #k
Based on logical AND or non-lookup
-A: represents and, while satisfied, defaults to the operation
-O: Represents or, satisfies a display
-not: Indicates a display that is not satisfied
Find by Time
-mtime +#: Find files with modified times greater than # days
-#: Find files with modified time less than # days
-atime +#: Find files with access times greater than # days
-ctime +#: Find files with state change times greater than # days
-mmin +#: Find files with modified time greater than # days minutes
Find based on permissions
-perm mode: Find files based on permissions, use MODE for exact lookups
-perm-mode: Indicates that each permission must match exactly
-perm/mode: Indicates that any one of the 9-bit permissions matches the lookup
Find action:
-print: Default value, display
-ls: Displays details of each file after matching in the form of a ls-l
-ok COMMAND {} \; Executes the command after the match. Note: This must be used here; is a terminator, otherwise a syntax error, {} is a file name placeholder
-exec COMMAND {} \; Executes the command after the match. Note: This must be used here; is a terminator, otherwise a syntax error, {} is a file name placeholder
Example: Find/-type f-exec chmod o-w {} \;
Finds files of type file in the current directory and removes write permissions for other users.
Find./-mtime +7-exec RM-RF {} \;
Find files in the current modified directory that are longer than 7 days and remove
Extended command
Xargs: Accepts commands from standard input and executes
Use pipe to accept, do not need to use {} placeholder, nor do you need \; end
Example:
Find/etc-size +1m-exec Echo {} >>/tmp/etc.bak \;
Find/etc-size +1m |xargs Echo >>/tmp/etc.bak
Both of these commands can be used to find files greater than 1M in/etc and write to the specified file
This article from "Liang Childe" blog, please be sure to keep this source http://iyull.blog.51cto.com/4664834/1884907
Linux Basics-File Lookup