Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux locate command

Linux locate command

Linux Command Reference Linux Command Reference

The Linux locate command is used to find files that meet certain criteria; it searches a database that stores file and directory names for files or directories matching a pattern.

In general, we only need to enter locate your_file_name to find a specified file.

Syntax

locate [-d ][--help][--version][范本样式...]

Parameters:

Example

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

Case-insensitively search for all files starting with r in the current user's home directory:

locate -i ~/r

Additional Notes

locate differs from find: find searches the hard disk, while locate only searches the /var/lib/slocate database.

locate is faster than find; it does not really search but queries a database. The file database is usually at /var/lib/slocate/slocate.db, so locate lookups are not real-time but based on database updates. It is generally maintained by the system, but you can also update the database manually with the following command:



updatedb

By default, updatedb runs once a day.

Linux Command Reference Linux Command Reference