Linux locate command
Linux Command大全
The Linux locate command is used to find documents that meet the conditions, it will go to the database that saves the document and directory names, and find documents or directories that meet the template style conditions.
In general, we only need to enter locate your_file_name you can find the specified file.
Syntax
locate [-d ][--help][--version][template style...]
Parameters:
-
-b, --basename -- Only match the base name of the path name
-
-c, --count -- Only output the number of found items
-
-d, --database DBPATH -- Use the database specified by DBPATH instead of the default database /var/lib/mlocate/mlocate.db
-
-e, --existing -- Only print entries for the currently existing files
-
-1 -- If is 1If it is, then start in safe mode. In safe mode, users will not see files that they do not have permission to see. This will slow down the speed because locate must get the file permission information from the actual file system.
-
-0, --null -- Individual entries with NUL on the output
-
-S, --statistics -- Do not search for entries, print statistics about each database
-
-q -- Quiet mode, no error messages will be displayed.
-
-P, --nofollow, -H -- Do not follow the trailing symbol link when checking if the file exists
-
-l, --limit, -n LIMIT -- Limit the output (or count) to LIMIT entries
-
-n -- Display at most n outputs.
-
-m, --mmap -- Ignored for backward compatibility
-
-r, --regexp REGEXP -- Use basic regular expressions
-
--regex -- Use extended regular expressions
-
-q, --quiet -- Quiet mode, no error messages will be displayed
-
-s, --stdio -- Ignored for backward compatibility
-
-o -- Specify the name of the database to be used.
-
-h, --help -- Display Help
-
-i, --ignore-case -- Ignore case
-
-V, --version -- Display Version Information
Online Examples
To find the passwd file, enter the following command:
locate passwd
Search for all files starting with sh in the etc directory:
locate /etc/sh
Ignore case search all files starting with r in the current user directory:
locate -i ~/r
Additional Notes
locate is different from find: find is looking on the hard disk, locate only in /var/lib/in the slocate database to find.
The locate speed is faster than find, it is not really searching, but checking the database, generally the file database is /var/lib/slocate/The slocate.db, so the locate search is not real-time, but based on the database update, usually maintained by the system itself, or the database can be manually upgraded, the command is:
updatedb
By default, updatedb is executed once a day.
Linux Command大全