Introduce to locate Command in Linux

locate allows users to quickly search for specific files in the Linux file system. The method is to first create a database that includes all file names and paths in the system, and then when searching, you only need to query this database without actually going into the file system.

locate – find files by name

locate reads one or more databases prepared by updatedb(8) and writes file names matching at least one of the
PATTERNs to standard output, one per line.

If –regex is not specified, PATTERNs can contain globbing characters. If any PATTERN contains no globbing
characters, locate behaves as if the pattern were *PATTERN*.

By default, locate does not check whether files found in database still exist (but it does require all parent
directories to exist if the database was built with –require-visibility no). locate can never report files
created after the most recent update of the relevant database.

In general distribution, the database creation is automatically performed in contab. For general users, just use the command:
locate your_file_name

Use

Example

locate netcat //Find all files called netcat

locate -n 100 apaches.log //Find all files named apaches.log, but only show up to 100
The locate command can quickly find files when searching for a database. The database is updated by the updatedb program. The updatedb is periodically created by the cron daemon.
The locate and find commands are similar but locate command uses the update program to first create an index database of all files and directory data on the hard disk. When you run locate command, you can find the index directly. The query speed is faster. It is managed by the operating system, but you can also issue an update directly to force the system to modify the index database immediately.