TranslateProject/sources/tech/20230103.3 ⭐️ Whereis Command in Linux and BSD with Examples.md

5.1 KiB
Raw Blame History

Whereis Command in Linux and BSD with Examples

Heres a beginners guide on understanding whereis command in Linux & BSD with several examples.

This article is part of the Linux command learning series.

whereis command

The whereis command is a command line program that helps you to find out the path or location of any binary executable, source file or manual page.

Before we show you how to use whereis command, lets look at the syntax.

Syntax

Heres the syntax for whereis command:

whereis [OPTIONS] FILE_NAME

The argument of whereis command is the program name or file name you want to search. The argument is mandatory.

By default, it searches for the program in the path defined in environment variables such as HOME, USER, SHELL, etc.

Lets take a look at some examples.

Examples of whereis command in Linux and BSD

A simple example of whereis command is below where I am trying to search firefox. In the output below, you can see the list of paths containing firefox files or executables displayed.

$ whereis firefox

firefox: /usr/bin/firefox /usr/lib64/firefox /etc/firefox /usr/share/man/man1/firefox.1.gz

Simple example of whereis command in Linux

The command with option -l displays the list of paths where it searches. For example:

$ whereis -l

bin: /usr/bin
bin: /usr/sbin
bin: /usr/lib
bin: /usr/lib64
bin: /etc
bin: /usr/games
bin: /usr/local/bin
bin: /usr/local/sbin
bin: /usr/local/etc
bin: /usr/local/lib
bin: /usr/local/games

If the whereis command doesnt find anything, it only shows the arguments name. For example, if I search nano in Linux where is it not installed, it outputs the following:

$ whereis nano
nano:

You can always add multiple arguments if you want to search for more. For example below command searches for both bash and nano, and this is the output:

$ whereis bash nano

bash: /usr/bin/bash /usr/share/man/man1/bash.1.gz /usr/share/info/bash.info.gz
nano: /usr/bin/nano /usr/share/nano /usr/share/man/man1/nano.1.gz /usr/share/info/nano.info.gz

You can also search for specific file types, such as binaries, using -b option. The following command only tells you the binary paths of nano.

$ whereis -b nano

nano: /usr/bin/nano /usr/share/nano

Similarly, the -s option searches for source files, and the -m option searches for manual pages.

$ whereis -m nano

nano: /usr/share/man/man1/nano.1.gz /usr/share/info/nano.info.gz

You can also combine the above options for a more extensive search. For example, the following command searches for nano and firefox binary, manual pages and for bash, only manual pages.

$ whereis -bm nano firefox -m bash

nano: /usr/bin/nano /usr/share/nano /usr/share/man/man1/nano.1.gz /usr/share/info/nano.info.gz
firefox-m:
bash: /usr/bin/bash /usr/share/man/man1/bash.1.gz /usr/share/info/bash.info.gz

Heres a summary of the options:

Option Description
-b Search only for binaries.
-m Search only for manual sections.
-s Search only for sources.
-u Search for unusual entries. A file is said to be unusual if it does not have one entry of each requested type. Thus whereis -m -u * asks for those files in the current directory which have no documentation.
-B Change or otherwise limit the places where whereis searches for binaries.
-M Change or otherwise limit the places where whereis searches for manual sections.
-S Change or otherwise limit the places where whereis searches for sources.
-f Terminate the last directory list and signals the start of file names, and must be used when any of the -B, -M, or -S options are used.

Closing Notes

I hope this article helps you to understand whereis command and its basics. You can also read thewhereis man pages to learn more. Let me know if you have any questions.

This article is part of the Linux command learning series.

Using Mastodon? Follow us at floss.social/@debugpoint


via: https://www.debugpoint.com/whereis-command-linux/

作者:Arindam 选题:lkxed 译者:译者ID 校对:校对者ID

本文由 LCTT 原创编译,Linux中国 荣誉推出