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

Linux basic part 5 basic commands-3

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

In linux, we often need to find certain files, the directory where the files are located, and so on. Then we need to use some basic file lookup class commands.

The main file lookup commands are as follows:

Which to view the full path to a command or executable file

Whereis displays binary file path, user manual file path, source file path

Locate cooperates with database to view file path

Find search hard disk to query specific files

Which

The function of the which command to search for the location of a system command in the specified PATH path and return the first search result. You can check whether a system command exists and the source file location where the command is located.

Command format:

Which [options] [-] programname [...]

Option parameters:

-a: list all commands that can be found in the PATH directory, not just the names of the first found commands

-- skip-alias: ignore aliases

Example 1: search the full path of the useradd command with root and ordinary users, respectively

Root users can find the full path to ifconfig

We found that the normal user prompted that the useradd command could not be found.

Because the which command searches for the command according to the directory within the PATH variable set by the user.

So, of course, different PATH settings find different commands!

Example 2: what happens when you use which to find which itself?

There are two which, one of which is a command alias, which is equal to the following string of commands + arguments

We can ignore aliases by appending the option-- skip-alias, as shown in the following figure

Example 3: find the full path of the cd command

The full path of the cd command cannot be found, which proves that the directory where the cd command is located is not defined in PATH.

Whereis

The whereis command displays the binary program file path, the user manual file path, and the source file path.

Command format:

Whereis [- bmsu] [- BMS directory... -f] filename...

Option parameters:

-b: search only the path of the binary file (commonly used)

For example:

Note that the average user cannot find adduser through the which command, but whereis can!

This is because the file adduser exists in the system itself, and the which command cannot be found because the PATH command has not been added to the specified directory

So, when you can't find some commands, you might as well look for the file search command.

-m: search only user manual file paths (commonly used)

For example:

-s: search only the source code path

-u: search for other file paths under the default path except the above three paths

-B: specifies the path to search for executable files.

-M: specifies the path to search for help files.

-S: specifies the path to search for source code files.

Locate

The locate command can quickly find the specified file when searching the database. The database is updated by the updatedb command, and the updatedb is periodically established by cron daemon. The locate command searches the database faster than the entire hard drive searches for files, but there is one drawback: the locate command cannot search for the most recent or renamed files, and requires the updatedb command to update the database. By default, updatedb runs once a day, and you can change the update time setting by modifying the / etc/crontab file.

Command format:

Locate [- eir]... PATTERN...

Option parameters:

-e: make sure that the file is indeed listed in the file system, otherwise, it will not be listed. (commonly used)

-I: ignore case (commonly used)

-r: the way the formal representation can be displayed later (commonly used)

Example 1: find all pwd-related files in the system

Example 2: find all the files in the / etc directory that start with sh

Not finished to be continued!

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

Database

Wechat

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

12
Report