The whereis command is used to find the paths of binary, source, and manual files for a specified command, similarly to the find command but consuming less memory.
Tutorial Details
Description | Whereis |
Difficulty Level | Low |
Root or Sudo Privileges | No |
OS Compatibility | Ubuntu, Manjaro, Fedora, etc. |
Prerequisites | whereis |
Internet Required | No |
Syntax of the Whereis Command
The whereis command takes two arguments, one being the option and the other being the filename.
$ whereis [OPTION] [FILENAME]
To search for multiple files at the same time, specify each of them using a space as a separator.
Working of Whereis Command
By default, when you execute any command in your system, it will search for the specified command in the path defined in your environmental files.
$ echo $PATH
Output:
For example, if you try to find the full path of the ls command, you will get the following result.
$ whereis ls
Output:
The above command will search for the “ls
” binary, source, and manual files from the specified paths in your environmental file.
Item | Description |
---|---|
/usr/share/man/* | It will contain the manual files |
/sbin, /etc, /usr/{lib,bin,ucb,lpp} | It will contain the binary files |
/usr/src/* | It will contain the source code files |
Printing the Single or Multiple Commands Path
The following command will print the ls command’s binary, source, and manual paths.
$ whereis ls
Output:
Get paths for multiple tools or commands by specifying each of them using space as a separator.
$ whereis nano vim
The above command will return all the (binary, source, and manual) paths related to Nano or Vim.
Printing the Full Path of Only Binaries
You can use the “-b
” flag with a command or tool name to only print its binaries or executable location.
$ whereis -b ls
Output:
Printing the Full Path of Only Manual Pages
The “-m
” flag with a command or tool name will only print the specified command or tool manual page path.
$ whereis -m ls
Output:
Printing the Full Path of Only Source
The following command with the “-s
” flag will print the source file for the specified command (only if your distribution has kept the source file).
$ whereis -s fs
Output:
Printing the Directories List Where the Whereis Command Searching
The whereis command will search for your specified argument in multiple directories that you can list using the “-l
” flag.
$ whereis -l ls
Output:
Searching for Unusual Entries
A file is said to be unusual when it does not have a single entry for each command or tool (binary, manual, or source).
For example, the wget command (or file) has multiple manual files that make it an unusual file.
$ whereis wget
Output:
As you can see above, the files with multiple binary, manual, and source files are considered unusual files.
Another example, from the “/bin/
” directory, if you want to list all the commands with multiple manual files, then use the “-u
” flag to specify the search for unusual files and the “-m
” flag to filter the search for only manual files with the wild card “*
“.
$ cd /bin
$ whereis -m -u *
Output:
Searching for the Keyword in a Specific Directory
By default, the whereis command will search for the tool or command in the specified path defined in your environmental file.
To limit the search location where the whereis is searching for binary, source, and manual files, use the “-B
” flag to assign a binary lookup path, the “-M
” flag for a manual path, and the “-S
” flag for a source path, with the “-f
” flag specifying the name of the command or tool.
For example, to override the binary lookup path, use the “-b
” flag to search only for binary in the specified path using the “-B
” flag and for the specified command or tool name using the “-f
” flag.
$ whereis -b -B /usr/bin/ -f ls
The above command will search for “ls
” binary files in the specified “/usr/bin
” path.
To search for the manual path in the limited location, use the “-m
” flag to only search for manual files, with the “-M
” flag specifying the path of the manual, and “-f
” to assign the name of the command or tool to be searched.
$ whereis -m -M /usr/share/man/man1/ -f ls
The above command will search for the ls command manual path in the specified path assigned to the “-M
” flag.
To search for the source path in the limited location, use the “-s
” flag to only search for source files, with the “-S
” flag specifying the custom path, and the “-f
” flag to assign the name of the command or tool to be searched.
$ whereis -s -S /usr/src/linux-* -f fs
The above command will search for the ps command source file in the specified path assigned to the “-S
” flag.
That was the last example.
I hope you enjoyed the article.
If you have any suggestions, feel free to share them in the comment section.
Join The Conversation
Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.