file Find Description:
Find eligible files on the file system
Locate: Non-real-time lookup, through the database to find, high efficiency, can be used to find more fixed files
Depending on the/var/lib/mlocate/mlocate.db database file, the files created before the database point in time can be found, and the newly created files cannot be searched after the point-in-time.
Update this database file: Update It once a day, or use UpdateDB to update the database
Fuzzy Search: The file path with the string to find, it is all searched, the search for the full path of the file
Case sensitive
-I for ignoring case
-n Specifies to list the first few lines Locate-n3 profile
-R using Regular expressions Locate-n3-r "\.conf$" (find top three files with end of Conf)
Find: Search by real-time
Real-time Find tool that searches the entire disk for file lookup
Grammar:
Find [option] ... [Find Path] [Search Criteria] [Handling Action]
Find path: Specify a specific target path; defaults to the current directory
Search criteria: Can be based on file name, size, type, permissions and other criteria to find, by default find all files under the specified path
Handling actions: Perform actions on eligible files, output to screen by default
Options
Search hierarchy, the Find command searches for recursive search by default, and each directory goes into
-maxdepth level The depth of the maximum search directory, the specified directory is 1th, also includes a directory smaller than the maximum level
-mindepth level minimum Search directory depth, can be used in conjunction with maxdepth, accurate to a certain layer
Search by file name and Inode:
-name "file name": Wildcard *,?, supported [],[^]
-iname ignoring case of file name
-inum "number" to find files based on inode number
-samefile "file name" to find files of the same inode
-inks n files with number of links n
-regex "PATTERN (matches full path of entire file)"
Depending on the owner, the genus Group looks for:
-user USERNAME: Find a file that belongs to USERNAME, can be used with the name option, and can be used together when looking for the owner of USERNAME and the file name is certain
-group GRPNAME: Finding genus Group for GRPNAME
-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
S: Socket file
D: Catalog file
L: Symbolic Link file
B: Block device files
C: Character device file
P: Pipeline File
Special conditions:
-prune: Cut the command, for example, except for the rest of a file, write-prune to the command you want to cut.
-path: Specified directory, used in connection with-prune
Combination conditions:
With:-A (default is not written, multiple conditions default is and relationship)
Or:-O
Non:-not,!
The law of Germany and Morgan:
(not a) or (not B) = Not (A and B)
(Not a) and (not B) = Not (A or B)
Example:
! A-a! B =! (A-o B)
! A-o! B =! (A-a B)
Find by File Size:
-size[+|-]
Common units: K,m,g,c (Byte)
Number: [-1]
such as: 6k (5k-6k), is greater than 5k and less than or equal to 6k
-: [0, number-1]
such as: -6k means [0-5k]
+: [number, unknown]
Such as: +6k represents more than 6k, does not include 6k
Find by TIME criteria:
The default is in days
-atime[+|-] Number,
Number: [+1]
such as: Less than 4 days in 3 days
+3:4 days above excluding 3 days
-3:0 days to 3 days excluding 3 days
-mtime: To modify the time
-ctime: State modification Time
In minutes:
-amin
-mmin
-cmin
To find a condition based on permissions:
-perm [/|-]mode
Mode: Exact match, such as Find-perm 664-type F, meaning to search the current directory file type is normal file and the permission is 664
/mode: One of the permissions of any class (U,g,o) object can match, or the relationship, such as: Find-perm/664-type F, meaning u,g,o arbitrarily think that the corresponding permissions can match
-mode: The relationship is expressed, each person must have corresponding permissions, 0 is not concerned about not as a search condition, such as: Find-perm-644-type, meaning that u,g,o must be the corresponding permissions to be able to match
Handling actions:
-print: Print to screen, default behavior
-ls: Can display the properties of a file, equivalent to "Ls-l", displayed in long format
-delete: Delete the found file (try not to use it)
-fls "file name": Save the found file to a file in a long format
-ok Commond {}\; : Executes the command specified by Commond for each file found, and the badge interactively asks the user to confirm that the-OK is changed to-exec when he does not want to have confirmation, for example: Find-name "*.conf"-exec cp {}/root/{} . bak \; is to back up all conf files under the current directory to/root and Add. bak as a suffix, curly braces for the found content, followed by "\;"
Parameter Substitution Xargs
Because many commands do not support piping to pass parameters, and the work is necessary to use, it produces the Xargs command
Some commands cannot handle too many parameters, and the command execution may fail, and the Xargs can be used to generate the arguments behind the command, just to resolve
Example:
LS f* | Xargs rm (use LS to find all files starting with F, each passed to Xargs for RM processing)
Find and Xargs format: Find | Xargs Command common mates (find searches out files that will be passed one by one to Xargs and then processed using the command after Xargs)
Linux File Lookup Introduction