In the Terminal (CLI), which and whereis are both used to locate the executable file of a command, but they have key differences:
which CommandPurpose: Finds the location of the executable that would be run if you type the command.
Search Path: It searches only the directories listed in the PATH environment variable.
Output: Returns the absolute path of the executable.
Example:Output:
which python
bash
CopyEdit
/usr/bin/python
whereis CommandPurpose: Locates the binary, source, and manual pages for a command.
Search Path: It searches predefined system locations (/bin, /sbin, /usr/bin, /usr/local/bin, etc.), not just PATH.
Output: Returns multiple paths if available (binary, source, and man pages).
Example:Output:
whereis python
python: /usr/bin/python /usr/lib/python3.9 /usr/share/man/man1/python.1.gz
| Feature | which |
whereis |
|---|---|---|
| Searches PATH? | ✅ Yes | ❌ No |
| Finds binaries? | ✅ Yes | ✅ Yes |
| Finds source code? | ❌ No | ✅ Yes |
| Finds man pages? | ❌ No | ✅ Yes |
| Outputs multiple locations? | ❌ No | ✅ Yes |
which when you need to know which exact executable will run when you type a command.whereis to find all possible locations, including the binary, source code, and documentation.