Whereis Command in Linux | Linuxize

[ad_1]

whereis is a command-line utility that allows you to find the location of the binary, source, and manual page files for a given command.

In this article, we will show you how to use the Linux whereis command.

How to Use the whereis Command #

The syntax for the whereis command is as follows:

whereis [OPTIONS] FILE_NAME...

When used without any options whereis search the binary, source and manual files for the command specified as an argument.

By default whereis searches for the command’s files in the hard-coded paths and directories listed in the environment variables
. Use the -l option to find the directories where the whereis command search for.

whereis -l

For example, to get information about the bash command, you would type the following:

whereis bash
bash: /bin/bash /etc/bash.bashrc /usr/share/man/man1/bash.1.gz

In the output above bash: is the command for which you want to get information, /bin/bash is the path to the binary file, /etc/bash.bashrc is the source file, and /usr/share/man/man1/bash.1.gz is the man page.

If the command you are searching for doesn’t exist, whereis will print only the command name.

You can also provide more than one arguments to the whereis command:

whereis netcat uptime

The output will include information about both netcat
and uptime
commands:

netcat: /bin/netcat /usr/share/man/man1/netcat.1.gz
uptime: /usr/bin/uptime /usr/share/man/man1/uptime.1.gz

To search only for the command binaries use the -p option.

For example, to find the location of the ping
command, you would type the following:

whereis -p ping
ping: /bin/ping

When searching only for the location of the command binary, prefer using the which
or type
commands.

To search only for the source files, use the -s option.

whereis -s command

If the source files exist, the whereis will print their locations.

The -m option allows you to search only for man files:

whereis -m command

To limit the locations where whereis searches for binaries use the -B options, for manuals the -M option, and -S for sources. Each option accepts a list of absolute paths to directories separated by space. The directory list must be terminated by the -f option that indicates the start of the filenames.

For example, to search for the cp
binary in the /bin directory you would type:

whereis -b -B /bin -f cp
cp: /bin/cp

The -u option tells whereis to search for unusual entries. Files that do not have exactly one entry of each requested type (binary, manual and source) are considered to be unusual files (commands).

For example, to search for all binaries in the /bin directory that doesn’t have manual pages or have more than one documentation you would type:

cd /binwhereis -m -u *

The wildcard character (*) after the -f option means all files in the current working directory
(/bin).

Conclusion #

The whereis utility is used to locate the binary, source, and manual files for a given command.

If you have any questions or feedback, please leave a comment below.

[ad_2]

Source link

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.