Discover how to instantly find any command on your system without endless searching!
Why which and whereis for commands in Linux CLI? - Purpose & Use Cases
Imagine you want to run a program on your computer, but you don't know where it is installed or which version will run if you type its name. You try typing the command, but sometimes it doesn't work or runs a different program than you expected.
Manually searching for a program's location means digging through folders one by one. This is slow and confusing, especially when many programs have similar names or multiple versions exist. You might run the wrong program by mistake, causing errors or wasted time.
The which and whereis commands quickly tell you where a program lives on your system. which shows the exact program that will run when you type its name, while whereis finds all related files like executables, source code, and manuals. This saves time and avoids confusion.
ls /usr/bin | grep program_name find / -name program_name
which program_name whereis program_name
You can instantly find and verify the exact program you want to run, making your work faster and more reliable.
When installing new software, you can use which to check if the command is ready to use, or whereis to find its documentation and binaries without guessing.
which shows the command that will run from your PATH.
whereis locates all files related to a command.
Both save time and reduce errors when working with commands.
Practice
which command do in Linux?Solution
Step 1: Understand the purpose of
Thewhichwhichcommand searches your PATH environment to find the executable file that runs when you enter a command.Step 2: Compare with other options
whereislists multiple locations including source and man files, not just the executable path. Manual pages are shown byman. Directory contents are shown byls.Final Answer:
Shows the full path of the executable that runs when you type a command -> Option CQuick Check:
which= executable path [OK]
- Confusing which with whereis
- Thinking which shows manual pages
- Assuming which lists all related files
ls command using which?Solution
Step 1: Recall basic
The basic syntax to find the path of a command is simplywhichsyntaxwhich command_name. No extra flags are needed for a single path.Step 2: Analyze options
Options like-lor--allare not standard or needed for basic usage. Adding-aor extra flags incorrectly after the command name is invalid.Final Answer:
which ls -> Option BQuick Check:
Simple syntax: which + command [OK]
- Adding unnecessary flags to which
- Placing flags after command name
- Using incorrect or unsupported options
whereis bash on a typical Linux system?Solution
Step 1: Understand
whereisoutput formatwhereisshows multiple locations: the binary executable path, source files if any, and manual page locations.Step 2: Analyze typical output for
On most systems,bashwhereis bashreturns the binary path like/bin/bashand the man page location like/usr/share/man/man1/bash.1.gz.Final Answer:
bash: /bin/bash /usr/share/man/man1/bash.1.gz -> Option AQuick Check:
whereis= binary + man files [OK]
- Expecting only one path from whereis
- Confusing whereis output with which output
- Thinking whereis returns error if command exists
which python3 but get no output. What is the most likely reason?Solution
Step 1: Interpret empty output from
Ifwhichwhichreturns nothing, it means it did not find the executable in any directory listed in your PATH environment variable.Step 2: Consider common causes
Most often, this means the program is not installed or its executable directory is not in PATH. Typing errors usually cause an error message, not empty output. The command itself rarely breaks, and firewalls do not hide executables.Final Answer:
Python3 is not installed or not in your PATH -> Option DQuick Check:
No output from which = command missing or PATH issue [OK]
- Assuming which is broken
- Blaming firewall for missing executable
- Ignoring PATH environment variable
gcc compiler including binary, source, and manual files. Which command should you use?Solution
Step 1: Understand the purpose of each command
whichshows only the executable path.locatesearches a database for filenames but may show unrelated files.findsearches the entire filesystem but is slow and may produce too many results.Step 2: Identify the command that shows binary, source, and manual files
whereisis designed to show all related locations for a command including binary, source, and man pages, making it the best choice.Final Answer:
whereis gcc -> Option AQuick Check:
whereis = binary + source + man files [OK]
- Using which to find all files
- Using locate without filtering results
- Running find without knowing its slowness
Ready to prove it?
Pass the test and this pattern moves unknown
