Detailed explanation of where is command

Time:2021-12-1

Linux / Unix can use the command where is to find the location of binary files (), source code and man Manual of a specific program and command. It seems that you can still see the location (path) of the software configuration file.

Command function:

    Find binary location
    Locate the location of the configuration file for the software
    Find source code file location
    View manual location

grammar

The basic syntax is as follows:

Copy code

The code is as follows:

whereis command

OR

Copy code

The code is as follows:

whereis program

OR

Copy code

The code is as follows:

whereis [options] program

OR

Copy code

The code is as follows:

whereis -BMS directory -f command

Use examples of whereis:

Find the location of the executable file, source code and man Manual of the date command. Enter:

Copy code

The code is as follows:

$ whereis date

The output is as follows:
2015626160819943.gif (582×414)

Animated gif 01: whereis command running on my Debian based server
How do I search only for binary locations?

Use the – b parameter:

Copy code

The code is as follows:

$ whereis -b date

How to search only the location of man manual?

Use the – M parameter:

Copy code

The code is as follows:

$ whereis -m date

How to search only the location of source code files?

Use the – S parameter:

Copy code

The code is as follows:

$ whereis -s date

Problem: there is a problem with the whereis – U parameter. According to the description of man whereis, – u is to search for files without binary files, source code files or man manuals. But the actual test found that it had nothing to do with this Mao.
An example in the man Manual:

A file is said to be unused if it does not have one entry of each requested type. Then the following example, asks for those files in the current directory which have no documentation:

Copy code

The code is as follows:

$ whereis -m -u *

First CD / bin, then execute the above command, and you will find   whereis -m -u *   And where – M*    The result is as like as two peas. The function of u is not reflected at all. Moreover, it is completely inconsistent with the description of the man document, because the files in the / bin directory have man documents. According to the meaning of the man document, the result should be empty, but the result is not empty.
How to restrict the search path?

Use the following parameters to limit the corresponding search path:

    – B / path / to / dir: restrict the search for binary files in the specified directory
    – M / path / to / dir: restrict the search of man manual files in the specified directory
    – S / path / to / dir: restrict the search of binary files in the specified directory

– B, – m, – s used in   – F must be added to any parameter   Parameter, and then specify the file name to search

Examples are as follows: only search ls and GCC in / bin directory:

Copy code

The code is as follows:

$ whereis -B /bin -f ls gcc

The results are as follows:

Copy code

The code is as follows:

ls: /bin/ls /usr/share/man/man1/ls.1.gz
gcc:

As you can see, there is no result when GCC searches for binary files in the / bin directory, indicating that GCC binary files are not in the / bin directory.

Problem: however, I found that although there are no GCC binaries in the / bin directory, using the above command still has output, not as I translated this article.

 

Example: This is also an example in the man manual. After testing, the -u parameter here is still inconsistent with that described in the man manual.

Find all in / usr / bin directory, and its man document is not in / usr / man / man1/   , And its source code file is not in / usr / SRC /

Copy code

The code is as follows:

# cd /usr/bin
# whereis -u -ms -M /usr/man/man1 -S /usr/src -f *

Test:

Copy code

The code is as follows:

#cd /bin
#whereis -u -m -M /root -f *

According to the man manual, the function of this command is to find all files in / bin whose man document is not in / root. Therefore, the result should be output, because there is no man Manual of any file in the / root directory. Yes, I was surprised to find that the result was empty.