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

What are the file lookup commands in linux

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces what are the file search commands in linux. It is very detailed and has a certain reference value. Friends who are interested must finish reading it.

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 update its database manually using the updatedb command:

$sudo updadb

Then we can search for new files.

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 above is all the contents of the article "what are the File search commands in linux?" Thank you for your reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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