Linux self-study journey-basic commands (locate command)

Linux self-study journey-basic commands (locate file search command)


Preface

1. In the previous section, we talked about the whereis and which search commands. We mainly talked about the basic functions and usage of the two commands. If you haven't read it yet, please click the link below to view it: whereis and which commands

2. In this section, let’s talk about a command locate that can search for files by file name.


Tip: The following is the content of this article

One, locate use

Locate can perform a search based on the file name and find the corresponding ordinary file.

  • Command name: locate
  • The full name of the command: find files by name
  • Location: /usr/bin/locate
  • Execution authority: all users
  • Function description: Use file name to find common files
命令格式
locate 【选项】 路径
常用选项:
-i:忽略大小写
-c:只显示查找到的数量

for example:

1. Find the passwd file (locate will search according to a database every time you find, the code here means to find the passwd file in the database, that is, it will find all the places in the system that contain the passwd file)
Insert picture description here


2. Locate is followed by the result to be checked; find all files starting with pa in the /etc directory.
Insert picture description here


3. The -c option is added to only display the number of files containing pass in the /etc directory
Insert picture description here

Two, locate search process

In fact, every time locate searches for ordinary files, it does not really search directly in the hard disk, but searches the database /var/lib/mlocate/mlocate.db, which is updated once a day by default. If you need to update manually, you can enter the updatedb command.


to sum up

In this section, we mainly talk about
{ 1. locate the use of 2. locate the search process } We will talk about a more commonly used command that can also find files by file name in the next section.



This is Jiehua, see you next time!

Guess you like

Origin blog.csdn.net/qq313088385/article/details/113505742