Linux / Commands / which, whereis, locate / Finding Command Locations

In Linux, which is mainly used to find executable files in PATH, whereis finds related files such as executables and manuals in predetermined locations. locate searches a pre-made filename database, so it can quickly find regular files as well, but the results may differ from the current state.

Which command should be used?

  • Executable File Path: Check with which find or the shell's command -v find to see which commands can be found in the current environment.
  • Executable Files and Manuals: Use whereis find to check whether programs and related manuals/sources are in known locations.
  • Search by file name: locate searches indexed paths, and if you need the most up-to-date information, you can use find to search a specified directory directly.

The search scope and results vary depending on the distribution, installed programs, user permissions, and settings. The output paths below are examples for explanation purposes and may not be the same on all systems.

Check executables with which and command -v

PATH is an environment variable that contains a list of directories to search when looking for a command to execute. The following command finds the path of an executable named find.

which find

For example, /usr/bin/find may be output. If no path is output, check whether the program is installed and verify PATH. However, the implementation of which and alias handling differs by system, so it is also a good idea to check built-in shell commands to see how the current shell interprets names.

command -v find
type -a find

In Bash, command -v shows the name or path used to call a command, and type -a shows the items found, such as aliases, functions, built-in commands, and executable files with that name. Shell built-in commands or aliases may not have a separate executable file path. You can verify their behavior in Bash built-in command description.

Finding related files with whereis

whereis searches for the program's executable files, source, and manual files in standard locations and the configured search paths.

whereis find

The results list the found paths after find:. If you want to see only the executable files, you can use whereis -b find; if you want to see only the manual files, you can use whereis -m find. If the file is not installed or outside the search path, it will not be displayed, so a lack of output does not necessarily mean the file is nowhere on the system.

In util-linux, whereis -l shows the search locations. For details on the search range, refer to util-linux whereis documentation .

Searching for file names with locate

locate searches for entries in the database created by updatedb that match a name or path. For example, the following command finds entries in the indexed paths that contain find.

locate find

The output can include not only executable files but also manuals or files with other names. Options may vary depending on the installed implementation, so check locate --help first. For example, in plocate, you can limit the results to up to 10 as follows.

locate -l 10 find

If the database is outdated, new files may be missing and already deleted paths may remain. Paths excluded from the search and the user's access permissions also affect the results. The distribution may periodically update the database, and in an environment where system administration is allowed, you can update it directly with sudo updatedb. Because this may scan a broad set of system directories, check the management policies before running it. Implementation and related manuals can be found in plocate official documentation.

Check installation status and latest files

locate may not be installed. For example, you can use the Ubuntu 24.04 plocate package, and in an environment with administrative privileges and access to the package repository, you can install it as follows.

sudo apt update
sudo apt install plocate

In other distributions or versions, package names and update methods may differ, so please consult the documentation for the respective distribution. If the database does not exist yet or is not up to date after installation, the administrator may need to initialize or update it.

To find the current file directly in your home directory without waiting for the database, do the following:

find "$HOME" -name 'example.txt'

This command searches the specified directory tree directly, so it may take longer than locate and cannot search directories for which you do not have access permissions. Replace example.txt with the actual file name you are looking for, and keep the quotes so that the search pattern is not expanded by the shell in advance.