The whereis command in Linux

The whereis command is a service utility which has a graphical interface that runs in the terminal and are useful when you need to know the location of the binary or source files on the computer.

It will help to find the manuals for the execution of certain commands. The linux whereis command is part of the util-linux package. let’s first look at its syntax.

Syntax whereis

To use the whereis I need to write the command in the following way:

options whereis ProgramName

If a search word is required, then, without listing the options you can do. In this case, the search will occur in all three types of files — and binary, and the source and manuals.

Options whereis

Here are the main options whereis:

  • -b – search for the binary files.
  • -B <dir> – searches only in user-specified directories.
    -m – find user manuals.
  • -M <dir> – searches the help files in those directories that the user has selected.
    -s – search source.
  • -S <folder> – will look for source files only where the user needs
  • -u – requests a withdrawal those teams who do not have the specified file type, or in the presence of two or more thereof. For example, whereis -m-u* it is useful to search for commands without a manual or dual manual.
  • -f – have to complete the list of directories, since it indicates that the character set is going immediately after it, is the name of the file.
  • -l – shows the directory in which the default takes place.

Instead of <folder> should set the path to the desired directory.

Examples of usage

If the user specifies a directory in which he wishes to search for files of a particular program, the utility uses the list of directories that are installed by default. To view their list:

whereis -l

To get all the information about a specific command (in our case bash), you need to type in the terminal

whereis bash

The screenshot shows the output if the command exists in the system:

  • bash is the name of the desired command;
  • /bin/bash – address, on which lies a binary file;
  • /etc/bash.bashrc – link to original file;
  • /usr/share/man/man1/bash.1.gz manual.

If the team for any reason does not exist, the output shows only the name.

Need to get information about several teams? There is no need to separately specify the search string for each of them. You can list all the names with a space, like this:

whereis uptime netcat

The screenshot shows that the data on each team are displayed on a new line. To search for source files, just type

whereis -s kword

Instead kword can be the name of any other program or command. If the source files are found, whereis will be informed of their location. Search of manuals is as follows:

whereis -m lmms

As in the previous case, lmms used for example. This place can be the name of any other team or program.

To search for information in certain directories using options -S, -M, -B should set the path to the desired directory, and not to forget the-f option before the command name about which you seek information. For example, to find the binary file cp command in /bin need to enter in the terminal:

whereis -b-B /bin -f cp

Using the-u option, it is easy to find any unusual entries (i.e. commands or programs that have no binary or source file of the manual; and those who have such files two and more). Here is an example to search for all the binaries in the directory /bin, which correspond to the above-mentioned characteristics:

cd /bin

whereis -m-u *

The asterisk as the mask specifies that the system displays all the available files that match the query.

Insights

Now you know how to use whereis linux for information about the location of certain files — the binary, source or reference. If you have something to say in addition to the above, also don’t forget to leave a comment.

Source: losst.ru

(Visited 17 times, 1 visits today)