You just installed a tool, but you no longer know if it’s located in /usr/bin, /usr/local/bin or elsewhere. The order whereis It can retrieve its binary, its source code, and its man pages. However, it doesn’t answer the most important question before any intervention: which file will your shell actually execute?
To avoid modifying the faulty installation, I cross my fingers. whereis with command -v And kind
The simplest use case is to provide the name of a command, without any options:
whereis bash
whereis ssh
whereis nginx
The output can contain multiple paths on the same line. whereis It searches for three types of files: the binary, the source code, and the manual documentation. It examines known Linux locations, and also takes into account MANPATHIt therefore does not simply scan the executables that your shell can launch.
whereis -b bash
whereis -s bash
-bsearches for binaries;-msearches for manual pages and Info files;-slook for sources.
An empty source search does not necessarily indicate that the program is incorrectly installed. Distributions often install the binary and manual without including the source code. /usr/srcTo see the files actually inspected on your machine, use:
whereis -l
There whereis manual page details these paths and the available options. This command is not a recursive file search. To find an arbitrary file in a directory tree, use the guide on find on Linux.
Check the command actually launched by the shell
If your goal is to know what will appear when you type python3, nginx Or montool, start with command -v :
command -v python3
command -v nginx
command -v mytool
This command follows the shell’s resolution. Depending on the name provided, it can display the path to an executable, a builtin, a function, or the definition of an alias. Its return code also allows you to properly check for the presence of a command in a script:
if command -v mytool >/dev/null 2>&1; then
echo "mytool is available"
else
echo "mytool is not found" >&2
fi
Do not use whereis for this test. When no file matches, it can simply display the name followed by a colon and end with a null return code. The script would then incorrectly conclude that the command exists.
kind goes further by explaining how Bash interprets the name:
cd type
ls-type
type -a ls
type -P ls
indicates thatCDis an internal shell command;ls-typeshows the first definition used;type -a lsdisplays aliases, functions, builtins and executables with that name;type -P lsforces a search for an executable file inPATH.
There GNU Bash type documentation This describes these results precisely. If you are using Zsh, Fish, or another shell, check its own documentation: the resolution of aliases and functions is not the same everywhere.
Understanding why “which” doesn’t tell the whole story
which remains common in tutorials:
which python3
which nginx
It typically looks for an executable in PATHThe problem is that it’s often an external program that doesn’t know the exact state of the current shell. Depending on the implementation and distribution, it might ignore an alias, a function, or a built-in. For a test in a shell script, command -v is more suitable. To understand a name collision in an interactive session, type -a provides more information.
A simple example illustrates the difference:
alias ll='ls -lah'
whereis ll
command -v ll
whereis cannot find a file named ll command -v And kind However, they see Bash’s well-known definition. The article on the alias under Linux explains how to check and bypass them without deleting your configuration.
Identify multiple installations of the same program
Collisions often occur after manual installation in /usr/local/bin, the addition of $HOME/.local/bin or the deployment of a version in /optStart by comparing the results:
whereis python3
type -a python3
command -v python3
type -P python3
readlink -f "$(type -P python3)"
whereis can display multiple binaries and manuals. type -a shows the versions that Bash finds in resolution order. command -v confirms the first choice, then resolves any potential symbolic link. Finally, check the package owner of the file:
dpkg -S "$(type -P python3)"
rpm -qf "$(type -P python3)"
pacman -Qo "$(type -P python3)"
Only run the command appropriate for your distribution. If no package contains the file, it may have come from a manual installation. Before replacing it, find its version, its actual target, and the services that use it. The tutorial on tar.gz archives under Linux shows why a copy in /usr/local/bin must remain traceable.
Bash also remembers certain paths that have already been resolved. After moving or replacing an executable, clear this cache and then check again:
hash -r
command -v python3
type -a python3
If the wrong file is loaded first, correct the order of PATH rather than deleting a random binary. The guide on PATH on Linux
Limit whereis to a specific folder
To control software installed under /optYou can replace the search paths for binaries or manuals. The option -f marks the end of the list of folders and the beginning of the names to search for:
whereis -b -B /opt/mytool/bin /usr/local/bin -f mytool
whereis -m -M /opt/mytool/share/man -f mytool
This targeted search allows you to check the contents of an installation without scanning the entire disk. It does not change either PATHnor the command executed by the shell. Therefore, keep the following order in mind before removing or replacing a program:
- use
command -vto find out the active definition; - launch
type -ato detect collisions; - resolve the links with
readlink -f; - check the file’s owner package;
- use
whereisto find the binaries and associated documentation.
With these checks, you know which file will be launched, where it comes from, and where to find its manual. You can then correct an installation or a… PATH without accidentally deleting the correct version.