Queries the pre-built file index database on the system
/var/lib/mlocate/mlocate.db
Note: If this file is deleted, locate will not work. You need to manually update the database (updatedb) or restart the system for locate to function again.
Relies on a pre-built index:
The index is constructed automatically during idle times on the system (periodic task /etc/cron.daily), and the administrator can manually update the database(updatedb)
Building the index requires traversing the entire root file system, which is resource-intensive.

2. Working Characteristics
The search is based on the full path of the file, not just the file name.
• Only searches directories where the user has read and execute permissions; if there are no permissions, even if the database has content, it will not be displayed for security reasons.
-i Case-insensitive search
-n # Only list the first # matching items
-r Supports regular expressions
A real-time search tool that performs file searches by traversing specified paths (find differs from other commands in that options are prefixed with a single -).
Compared to locate, find has powerful functionalities; it can search not only based on file names but also by permissions, file types, sizes, and many other criteria, making it widely applicable.
1. Working Characteristics
• Search speed is slightly slower
• Precise search (can achieve fuzzy queries through regular expressions and wildcards)
• Only searches directories where the user has read and execute permissions
find [OPTION]… [search path] [search criteria] [action]
Search path: specify the exact target path; defaults to the current directory
Search criteria: specified search standards, which can include file name, size, type, permissions, etc.; defaults to finding all files in the specified path
Action: operations to perform on the files that meet the criteria, defaults to outputting to the screen, with many other possible actions.
–maxdepth level Maximum search directory depth; -1 specifies the directory as level 1, the current directory.
–mindepth level Minimum search directory depth

2) Based on File Name and Inode Search:
-name : Exact search based on name, supports using wildcard characters *, ?, [], [^], etc.
-iname : Case-insensitive exact search based on name
-inum : Search based on inode
-samefile name : Search based on the same inode number (find hard links)
-links n Files with n hard links
-regex “PATTERN” : Supports regular expressions, defaults to (emacs standard regex), querying the range expressed by the regex
Example: “.*\/ [a-z].*” searches for all files starting with a lowercase letter
-regextype egrep -regex Supports egrep standard regular expressions
3) Based on Owner and Group Search:
-user USERNAME : Search for files owned by the specified user (UID)
-group GRPNAME: Search for files belonging to the specified group (GID)
-uid UserID : Search for files owned by the specified UID number
-gid GroupID : Search for files belonging to the specified GID number
-nouser : Search for files without an owner
-nogroup : Search for files without a group

4) Based on File Type Search:
l: Symbolic link files (soft links)
s: Socket files (/dev/log)
b: Block device files (/dev/sda)
c: Character device files (/dev/tty)

5) Based on File Size Search:
find -size [+|-]#UNIT Search based on file size
Common units: k, M, G, c (byte)
#UNIT: (#-1, #] For example: 6k means (5k,6k]
-#UNIT: [0,#-1] For example: -6k means [0,5k]
+#UNIT: (#,∞) For example: +6k means (6k,∞)
-atime [+|-]#, (access time)
#: [#,#+1) For example: 3 means [3,4)
+#: [#+1,∞) For example: +3 means [4,∞)
-#: [0,#) For example: -3 means [0,3)
-mtime (modification time) works the same as above
-ctime(metadata change time) works the same as above
In “minutes“: (works the same as above)

7) -perm Search based onpermissions:
mode: Exact permission match
+mode[/mode] Any one of the object permissions (u,g,o) only needs to match one bit, OR relation, + Phased out since CentOS 7
-mode Every object must have the specified permission, AND relation
8) Combined Condition Search:
AND: -a can be omitted Example: find -nouser [-a] -nogroup
(NOT A) OR (NOT B) = NOT(A AND B) !A -o !B = !(A -a B)
(NOT A) AND (NOT B) = NOT(A OR B) !A -a !B = !(A -o B)
-delete Directly delete the found files without asking.
-ls Long list the found files, similar to ls -li
-fls file Long list the found files and import them into the specified file.
> file Imports the query results into file >> file Appends the query results to file
-ok command
Treats the found files as arguments for the next command (interactive) (do not forget the last
is a fixed format)
-exec command
Treats the found files as arguments for the next command (non-interactive)
{ }: Used to reference the names of the found files themselves
5. Parameter Replacement with xargs (“Universal” Parameter Passing)
xargs is used to generate parameters for a command,
Purpose: Many commands do not support pipe | to pass parameters, xargs can pass all parameters
For example: find /etc/ -name “*.sh” | xargs ls -l
Some commands cannot accept too many parameters; command execution may fail, and xargs can solve this
For example: touch, rm cannot execute more than a certain number of parameters (about 30000)
You can echo {1..30000} | xargs touch
The autumn recruitment has ended, if everyone does not prepare well, it will be hard to find a good job in the spring recruitment.
Here’s a job package for everyone, you can brush up on your spring recruitment and find a good job!
