which vs whereis vs locate: Find Where a Command Lives
What You Will Learn
which, whereis, and locate. They each do something different — let's go through them one by one.By the end of this article you will be able to:
- Use
whichto find the executable pathA string that describes the location of a file or directory. of a command - Use
whereisto find the binary, man page, and source at once - Use
locateto search for any file by name, fast - Know which tool to reach for in which situation
1. which — "Which executable does my shell actually run?"
Conclusion:
whichsearches PATH in order and prints the one executable your shellAn interactive program that reads the commands you type and runs them. runs.
which?python, which one runs? which tells you exactly which file your shell picks up.Basic usage
which python3
/usr/bin/python3
which searches the directories listed in your PATH environment variableA named value that the shell or a program can look up while running., in order, and prints the first match it finds.
which git
/usr/bin/git
which only searches directories in $PATH. Run echo $PATH to see which directories are included.
When a command is not found
which nonexistent-command
No output (exit code 1). Some distributions print a message like:
which: no nonexistent-command in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin)
Useful when multiple versions are installed
which python which python3
/usr/bin/python /usr/bin/python3
You can see at a glance which version each name maps to.
Check aliases and shell builtins too: type -a / command -v
which cd on Ubuntu and got nothing. But cd always works...cd is built into the shell (bash) itself. On Ubuntu and Debian, which only looks for files in your PATH, so it can't see shell builtins or aliases — it prints nothing and returns exit code 1. For those, use type -a.Fedora and RHEL-family systems behave differently. The bash package installs wrapper scripts such as /usr/bin/cd for the builtins, so which cd prints that path, and in interactive shells /etc/profile.d/which2.sh makes which show aliases and shell functions as well. Whatever the system, type -a is the reliable way to see what actually runs. (Source: Fedora bash.spec, Fedora which2.sh, CentOS Stream 9 bash.spec / which2.sh, retrieved 2026-09-25)
type -a cd type -a ls
cd is a shell builtin ls is aliased to `ls --color=auto' ls is /usr/bin/ls ls is /bin/ls
type -a lists every match — aliases, shell builtins, and executables in your PATH. The first line is what actually runs. (Both /usr/bin/ls and /bin/ls appear on systems where /bin is a link to /usr/bin.)
Inside a shell script, use command -v to check whether a command is available. It is defined by POSIX.
command -v git command -v cd
/usr/bin/git cd
When nothing matches, it prints nothing and returns exit code 1, so you can use it in a condition: if command -v git >/dev/null 2>&1; then ... fi.
2. whereis — "Show me the binary, man page, and source together"
Conclusion:
whereisfinds the binary, man page, and source at once, ignoring your PATH.
which. What does whereis add?which only shows the one executable your shell would run right now. whereis shows you the binary, the man page, and sometimes the source — all at once. And it's not limited to your current PATH.Basic usage
whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
/usr/bin/ls is the executable. /usr/share/man/man1/ls.1.gz is the compressed man page.
whereis python3
python3: /usr/bin/python3 /usr/lib/python3 /usr/share/man/man1/python3.1.gz
What each field means
| Field | Content |
|---|---|
First path after command: |
Executable binary |
Path under /usr/share/man/ |
Man page |
Path under /usr/lib/ |
Libraries or supporting files |
Path under /usr/src/ |
Source code (if installed) |
Filtering with options
whereis -b ls # binary only whereis -m ls # man page only whereis -s ls # source only
ls: /usr/bin/ls ls: /usr/share/man/man1/ls.1.gz ls:
Unlike which, whereis searches a fixed set of standard system directories (/bin, /usr/bin, /usr/local/bin, etc.) regardless of your current PATH. That means it can still find a command even if PATH is misconfigured.
3. locate — "Search for any file by name, fast"
Conclusion:
locatequeries a prebuilt database to find any file by name, very fast.
locate for?locate is much faster than find for that.Basic usage
locate ssh_config
/etc/ssh/ssh_config /usr/share/doc/openssh-client/examples/ssh_config
Why is it so fast?
locate does not scan the filesystem in real time. It queries a pre-built database (index), which is why it returns results almost instantly.
The database is typically rebuilt once a day by a scheduled job running updatedb. Files created after the last update will not appear in locate results until the database is refreshed.
Rebuild the database manually
sudo updatedb
Run this after creating new files, then locate will find them.
Case-insensitive search
locate -i README
/home/user/projects/readme.md /usr/share/doc/curl/README /usr/share/doc/git/README.md
Combine with grep to filter results
locate nginx | grep conf
/etc/nginx/nginx.conf /etc/nginx/conf.d/default.conf
Count matches without listing all paths
locate -c python
248
If locate is not installed, install the plocate package (sudo apt install plocate / sudo dnf install plocate). See "Common Questions and Pitfalls" for how this differs between distributions.
4. Choosing the Right Command
Conclusion: Use
whichfor paths,whereisfor related files,locateto search names.
| Goal | Command |
|---|---|
| Find the exact executable your shell would run | which |
| See the binary, man page, and source together | whereis |
| Search for any file by name, quickly | locate |
| Search for newly created files (not yet in DB) | find |
| Find out what a name really is (alias, builtin) | type -a |
Common real-world examples
- Is
pythonPython 2 or Python 3? →which python - Where is git's man page? →
whereis git - Where is
nginx.conf? →locate nginx.conf - Just installed something and need to find it now →
sudo updatedb && locate filename
5. Common Questions and Pitfalls
Conclusion: When
whichis empty, usewhereisorlocate; runupdatedbfor fresh data.
Q. which returns nothing — is the command really installed?
which node and got nothing. I thought I installed it...whereis node and locate node | grep bin first. Those cast a wider net. Also check echo $PATH — maybe the install directory just isn't in your PATH.# Check PATH echo $PATH # Broader search whereis node # Search common bin directories locate node | grep "/bin/"
Q. locate returns stale results
If a file you just created does not appear:
sudo updatedb locate the-file-you-want
Q. locate command not found
On current major distributions, locate comes from the plocate package. plocate is a compatible reimplementation of the older mlocate, so locate and updatedb work the same way.
# Ubuntu 22.04 and later / Debian 12 and later sudo apt install plocate # Fedora 36 and later / Rocky Linux 10, AlmaLinux 10, etc. sudo dnf install plocate
On older distributions, use the mlocate package.
# Ubuntu 20.04 / Debian 11, etc. sudo apt install mlocate # Rocky Linux 9 / AlmaLinux 9, etc. sudo dnf install mlocate
| Distribution | Package that provides locate |
|---|---|
| Ubuntu 20.04 / Debian 11 | mlocate (plocate is also available on Debian 11) |
| Ubuntu 22.04 / Debian 12 | plocate (mlocate is a transitional dummy package that pulls in plocate) |
| Ubuntu 24.04 and later / Debian 13 | plocate (no mlocate package) |
| Fedora 36 and later | plocate (replaces mlocate; the two cannot be installed together) |
| Rocky Linux 9 / AlmaLinux 9 | mlocate |
| Rocky Linux 10 / AlmaLinux 10 | plocate |
(Source: Ubuntu Packages Search: mlocate / plocate, Launchpad: mlocate in Ubuntu Focal, Debian package search: mlocate / plocate, Fedora Changes/Plocate as the default locate implementation, Rocky Linux 9 BaseOS / 10 BaseOS, AlmaLinux 9 BaseOS / 10 BaseOS, retrieved 2026-09-25)