Cyberithub

11 Useful whereis command examples in Linux

Advertisements

In this article, I will take you through 11 Useful whereis command examples in Linux. whereis is used to locate the binary, source and manual files for the specified command names. There are other open source utilities available in Linux which can perform similar kind of tasks that we will see in later articles. Here we will keep our focus on the usage of whereis command.

Synopsis

whereis [options] [-BMS directory... -f] name...

10 Useful whereis command examples in Linux

Useful whereis command examples in Linux

Also Read: 5 Best Steps to Install Snap Command on Ubuntu 20.04

Example 1: How to Check whereis command version

If you want to check whereis command version then you need to use whereis --version command as show below. As you can see whereis utility is a part of util-linux version 2.34.

root@localhost:~# whereis --version
whereis from util-linux 2.34

 

Example 2: How to use whereis command

You can use whereis utility to find the binary path and manual page location of Linux commands. In this example, we are looking for the binary path and manual page of who, date and touch utilities using whereis who date touch command as shown below.

root@localhost:~# whereis who date touch
who: /usr/bin/who /usr/share/man/man1/who.1.gz
date: /usr/bin/date /usr/share/man/man1/date.1.gz
touch: /usr/bin/touch /usr/share/man/man1/touch.1.gz

 

Example 3: How to Locate the Binaries of a Linux Command

To locate only the binaries of a Linux command, you need to use -b option with whereis command. In this example, we are looking for the date binary path using whereis -b date command as shown below.

root@localhost:~# whereis -b date
date: /usr/bin/date

 

Example 4: How to Locate the Manuals of a Linux Command

To locate only the manuals of a Linux command, you need to use -m option with whereis utility. In this example, we are looking for the manuals of date command using whereis -m date command as shown below.

Advertisements
root@localhost:~# whereis -m date
date: /usr/share/man/man1/date.1.gz

 

Example 5: How to locate the Source file of a Linux Command

If the source file of a Linux binary is available then it can be searched through -s option. In this example, we are searching the source file of date command using whereis -s date as shown below.

root@localhost:~# whereis -s date

 

Example 6: How to Limit the Directory search of a Command

If you want to limit the directory search of a Linux command then you need to use -B option. In this example, we are looking for the binary path of who command by limiting our search under /usr/bin path only using whereis -B /usr/bin -b who command as shown below.

root@localhost:~# whereis -B /usr/bin -b who
who: /usr/bin/who

 

Example 7: How to Check command with unusual entries

If you want to check a command that have unusual entries then you need to use -u option. In this example, we are checking all the commands in current directory that have unusual entries in the Server using whereis -u * command as shown below.

root@localhost:~# whereis -u *
snap: /usr/bin/snap /usr/share/man/man8/snap.8.gz

 

Example 8: How to Check the List of whereis effective Lookup Path

If you want to see the list of lookup path which whereis utility uses to locate the binary, source and documentation files of a linux command then you need to use -l option. In this example, we are checking the list using whereis -l command as displayed below.

root@localhost:~# whereis -l
bin: /usr/bin
bin: /usr/sbin
bin: /usr/lib/x86_64-linux-gnu
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
bin: /usr/include
.....................................

 

Example 9: How to Reset Search Path for Subsequent Patterns

There are few options like -B, -M and -S available with whereis command which reset search path for subsequent patterns. This can be easily shown with the help of below example where we are searching for "who" man pages in all default paths, but for "date" in the /usr/share/man/man1 directory only using whereis -m who -M /usr/share/man/man1 -f date command.

root@localhost:~# whereis -m who -M /usr/share/man/man1 -f date
who: /usr/share/man/man1/who.1.gz
date: /usr/share/man/man1/date.1.gz

-m : Search for manuals. More on whereis Man Page.

-M : Limit the search places

-f : Terminates the directory list and signals the start of filenames.

Example 10: How to Check all the options available with whereis command

If you want to check all the options available with whereis command then you need to use whereis --help command as shown below.

root@localhost:~# whereis --help

Usage:
whereis [options] [-BMS <dir>... -f] <name>

Locate the binary, source, and manual-page files for a command.

Options:
-b search only for binaries
-B <dirs> define binaries lookup path
-m search only for manuals and infos
-M <dirs> define man and info lookup path
-s search only for sources
-S <dirs> define sources lookup path
-f terminate <dirs> argument list
-u search for unusual entries
-l output effective lookup paths

-h, --help display this help
-V, --version display version

 

Example 11: How to Check the Man Page of whereis command

If you want to check the man page of whereis command then you need to use man whereis command as shown below.

root@localhost:~# man whereis
WHEREIS(1) User Commands WHEREIS(1)

NAME
whereis - locate the binary, source, and manual page files for a command

SYNOPSIS
whereis [options] [-BMS directory... -f] name...

DESCRIPTION
whereis locates the binary, source and manual files for the specified command names. The supplied names are first stripped of leading pathname
components and any (single) trailing extension of the form .ext (for example: .c) Prefixes of s. resulting from use of source code control are
also dealt with. whereis then attempts to locate the desired program in the standard Linux places, and in the places specified by $PATH and $MAN‐
PATH.

The search restrictions (options -b, -m and -s) are cumulative and apply to the subsequent name patterns on the command line. Any new search re‐
striction resets the search mask. For example,

whereis -bm ls tr -m gcc

Leave a Comment