Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

In addition to the find command, there are so many file search commands!

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

The file search command is much more than a find command, and there are many more. This article on the Linux file search command for a popular science, so that you can find the files you need in a short time.

Finding files in the system is an essential skill for all engineers (whether you are using Windows, Linux, or MacOS). For the Linux operating system, a single find command can do a lot of search work.

However, the file search command is much more than a find command, there are many more. This article on the Linux file search command for a popular science, so that you can find the files you need in a short time.

1. Find

The find command is probably the most classic command, and the first thing that comes to mind when it comes to search tools is the find command. However, the find command is so powerful that if you want to introduce its functions, you may have to write several articles.

So, here is a lazy introduction to the most basic way to find a file according to its name. If we want to search for all .sh files in the current directory (and its subdirectories), we can search like this:

2. Locate

Locate is another command that searches for files by file name. Unlike the find command, the locate command does not need to specify a path, just search.

Instead of going directly to every corner of the system to search for files, this command searches under a database called mlocate.db. This database, located at / var/lib/mlocate/mlocate.db, contains indexes of all files in the system and is automatically updated by the cron tool every morning.

Because of this, locate searches much faster than the find command, because it searches directly in the database and is naturally faster.

After the locate command finds the file, it directly displays the absolute path to the file, such as:

But the drawback of the locate command is that it cannot search for files created that day because its database is only updated once a day in the morning. For example, I'm creating a new file now, and locate can't find it:

To solve this problem, we can use the updatedb command to manually update its database: sudo updadb

3. Which

The which command is mainly used to find the location of the executable, which specifies the values under the $PATH and $MANPATH environment variables. By default, the which command displays the first storage location of the executable:

If an executable is stored in more than one location, you can use the-an option to list all locations.

If you want to find more than one file at a time, you can follow the which command directly.

4. Whereis

The whereis command looks for binaries, source code, and files that contain given query keywords in the system's default installation directory (usually the software installed by default when you have root permissions). (the default directory has paths like / bin, / sbin, / usr/bin, / usr/lib,/usr/local/man, and so on).

It generally includes the following three parts:

Path to the binary file

Source path of the binary file

Path to the corresponding man file

For example, we now search for the ls command:

We can use the-b option to search only the location of the executable file, use the-B option to specify the search location, and use the-f option to list information about the file.

Similarly, we can use-s to limit the search only to the source path,-m to search the man page path,-s to specify the path to search for source code files, and-M to specify the path to search for help files.

The original text is from: https://www.linuxprobe.com/find-locate.html

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report