Linux Find command in the detailed
A. Find command
The Find command is a handy tool for locating files in a Linux system.
The Find command is a real-time lookup tool that finds the target file by iterating through all the files under the specified starting path, based on the file hierarchy. Its search accuracy is high, real-time high, but the corresponding, the query speed will be reduced.
Ii. detailed Instructions
The general syntax for the Find command is below:
find [Options] [Find starting path] [find condition] [processing action]
1, OPTIONS: generally not used;
2, find the starting path: Specify the specific search target starting path, the default current directory;
3, search criteria: The specified search criteria, according to the file name, size, type, affiliation, permissions and other criteria, the default is the path of all the files;
4. Handling action: The default is output to standard output (-print) for actions that match the search criteria.
A detailed analysis is required to find the condition and handle the action.
Search criteria:
A) Search by file name:
-name "pattern": Find support file name glob style matching;
-iname "pattern": Find support file name Glob style matching, and case-insensitive;
-regex "pattern": find supports regular expression matching, but it matches the entire path rather than its name; be aware
b) search based on file affiliation:
-user Username: Find all files belonging to the master specified user
-group Groupname: Find all files belonging to the specified group of users
-uid uid: Finds all files belonging to the master specified UID
-gid GID: Find all files belonging to the group's specified GID
-nouser: Find all files that are not owned by the owner
-nogroup: Find all files that are not owned by group
c) Search by file type:
-type type:f, find common Files
d, catalog file
L, find the symbolic link file
B, find the block device file
C, find the character device file
s, finding socket file
P, find the named pipe file
d) Search by file size:
-size [+|-] #UNIT
Common units, K, M, G, default units are bytes
#UNIT: (#-1,#], find the exact size of the file with this unit as precision
-#UNIT: [0,#-1], find files of size 0 to #-1, including files of #-1 size
+ #UNIT: (#,∞), find # to infinity size files, not including # size files
e) Find by timestamp: (Because the timestamp is a change from the past, it can be understood as a negative number, such as-7 is 7 days ago to the present)
In "Days" as the unit:-atime,-mtime,-ctime
# : (#-1,#], find files with timestamp changes in # # days
-#: (#,0], find files that have time stamp changes from # days to now
+#: (∞,#-1], find files with timestamp changes #-1 days ago
In minutes:-amin,-mmin,-cmin
The range represents the same usage as above.
f) Search According to file permissions:
-perm [ /|-]mode
Mode: Exact search for files with matching permissions
/mode: Find any one (rwx) eligible file (existence "or" relationship between 9-bit permissions) in the permissions of any class of users (Ugo)
-mode: find every file in the permissions of each class of user (with "and" relationship between 9- bit permissions)
g) Combination Lookup:
With:-A, default combination logic (can be omitted), find files that meet 2 conditions at the same time
Or:-O to find files that meet any one of the criteria
Non:-not,! Find all files contrary to the condition
2 formulas:! A-a! b=! (A-o B)
! A-o! b=! (A-a B)
Handling actions:
-print: Output to standard output, default
-ls: Similar to Ls-l
-delete: Delete the found file
-fls/path/tosomefile: Save details of all found files to the specified file
-ok COMMAND {} \; : Executes the command represented by commands on each file found, and each action is confirmed by the user ({}: References to found files )
-exec Command {} \;: executes commands for each file that is found
Note: Find passes the file path found to the following command, it is first to find out all eligible file paths, and one-time pass to the following command;
This article is from the "give me a piece of two-foil" blog, please be sure to keep this source http://theneverland.blog.51cto.com/10714090/1726342
Find command explanation