Linux locate command
The Linux locate command is used to find documents that meet the criteria. It searches the database that stores document and directory names for documents or directories that match the pattern.
In general, we only need to enterlocate your_file_nameto find the specified file.
Syntax
locate [-d ][--help][--version][范本样式...]
Parameters:
- -b, --basename -- Only match the base name of the path name
- -c, --count -- Only output the number of matches found
- -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 currently existing files
- -1 -- If it is 1, enable secure mode. In secure mode, users will not see files that they do not have permission to view. This will slow down the speed because locate must obtain the file permission data from the actual file system.
- -0, --null -- Separate entries with NUL on output
- -S, --statistics -- Do not search entries, print statistics about each database
- -q -- Quiet mode, no error messages will be displayed
- -P, --nofollow, -H -- When checking file existence, do not follow trailing symbolic links
- -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 expression
- --regex -- Use extended regular expression
- -q, --quiet -- Quiet mode, no error messages will be displayed
- -s, --stdio -- Ignored for backward compatibility
- -o -- Specify the name of the database
- -h, --help -- Display help
- -i, --ignore-case -- Ignore case
- -V, --version -- Display version information
Examples
To find the passwd file, enter the following command:
locate passwd
Search the etc directory for all files starting with sh:
locate /etc/sh
Ignore case and search the current user directory for all files starting with r:
locate -i ~/r
Additional Notes
locate is different from find: find searches the hard disk, while locate only searches in the /var/lib/slocate database.
locate is faster than find. It does not actually search, but queries the database. Generally, the file database is in /var/lib/slocate/slocate.db, so locate's search is not real-time, but is based on the database update. Usually the system maintains it by itself, and you can also manually update the database with the command:
updatedb
By default, updatedb is executed once a day.
Other Extensions
Linux Command Reference