Home > File & Directory Management > whereis

Guide to the whereis Command: Finding the Location of Commands/Files

`whereis` command is used in Linux and Unix-like operating systems to locate the binary, source code, and manual page files of a command. It is useful when you need to quickly determine the path of a specific program or file installed on the system, especially when checking the existence of a program in shell scripts or dynamically referencing paths. Through this guide, learn how to use the `whereis` command and its main options.

Overview of whereis

`whereis` command finds the location of a program similar to the `which` command, but while `which` only finds executables specified in the `PATH` environment variable, `whereis` searches predefined standard paths to find binaries, sources, and manual pages. This is mainly used by system administrators to check the installation path of programs or to determine if a specific file exists in the system.

Main Functions of whereis

`whereis` command is mainly used for the following purposes:

Main Use Cases

  • Checking program installation paths: `whereis` allows you to quickly find where a specific command is installed.
  • Identifying source code locations: If the source code of a program is installed on the system, it finds its location.
  • Verifying manual page locations: It finds where the `man` page files are located.
  • Debugging system environment configurations: When a command fails to execute due to `PATH` settings or other environment variable issues, it helps diagnose problems by identifying the actual file location.

`whereis` vs `which` vs `find`

There are several tools for finding command locations, each with different purposes and search methods.

  • `whereis`: Quickly searches for binaries, sources, and manual pages only in predefined standard paths. Operates independently of the `PATH` environment variable.
  • `which`: Finds the full path of executable binary files within directories defined in the `PATH` environment variable. Useful when you want to know where a command will execute.
  • `find`: Searches for files based on various criteria such as file name, type, modification time, etc., throughout the entire file system or within specified directories. Most powerful but can be the slowest.

Main Options for the whereis Command

`whereis` command provides options to specify the types of files to search for (binary, source, manual) or to limit the search paths.

1. Basic Searching and Filtering

2. Specifying Search Paths

Generated command:

Try combining the commands.

Description:

`whereis` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Learn how to efficiently find the location of commands, sources, and manual pages in the system through various usage examples of the `whereis` command.

Finding Locations of Binary, Source, and Manual Page for `ls` Command

whereis ls

Outputs the locations of all files related to the `ls` command (executable files, source files, manual page files).

Finding Only the Binary File Location of `bash` Shell

whereis -b bash

Outputs only the location of the executable binary file of the installed `bash` shell on the system.

Finding Only the Manual Page Location of `nginx` Command

whereis -m nginx

Outputs where the `man` page file of the `nginx` command is located.

Searching for Binary Files Only in Specific Paths

whereis -b -B /usr/local/bin,/opt/bin my_custom_command

Searches for the `my_custom_command` binary only in the `/usr/local/bin` and `/opt/bin` directories instead of the default search paths.

Attempting to Search for a Non-Existent Command

whereis nonexistent_command

When searching for a `nonexistent_command` that does not exist in the system, nothing will be output or a message stating that the file does not exist will be displayed.


Same category commands