Home > Article > Operation and Maintenance > What is the use of the linux locate command?
linux locate command is used to find files or directories, the syntax is "locate [OPTION]... [PATTERN]...". The locate command does not search a specific directory, but a database "/var/lib/mlocate/mlocate.db", which contains all local file information; the system automatically creates this database and updates it automatically once a day.
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
The locate command in Linux is used to find files or directories. The locate command is much faster than find -name
because it does not search a specific directory, but a database /var/lib/mlocate/mlocate.db
.
Linux locate command
The database used by the Linux locate command contains all local file information. The Linux system automatically creates this database and updates it automatically every day.
Therefore, when we use whereis and locate to search for files, we sometimes find deleted data, or the file has just been created but cannot be found. The reason is that the database file has not been updated.
In order to avoid this situation, you can use the updatedb command to manually update the database before using locate. The entire locate work is actually composed of four parts:
Composition | Description |
---|---|
/usr/bin/updatedb | is mainly used to update the database, which is automatically completed through crontab. |
/usr/bin/locate | Query file location |
/etc/updatedb.conf | updatedb’s configuration file |
/var/lib/mlocate/mlocate.db | File that stores file information |
Syntax
locate [OPTION]... [PATTERN]...
Parameters
Description | |
---|---|
Find file file | |
Ignore case to find file file |
locate Find fileSyntax
locate fileCase 1
We use the locate command to find the file starting with my in the etc directory. The specific command is as follows:
locate /etc/my
After running, the terminal output is as follows:
We see that we used the locate command to find all files starting with my in the etc directory.
Case 2We use the locate command to find the Linux installation file. The specific command is as follows:
locate install.log
After running, the terminal output is as follows:
Related recommendations: "
Linux Video TutorialThe above is the detailed content of What is the use of the linux locate command?. For more information, please follow other related articles on the PHP Chinese website!