0
0
Linux CLIscripting~20 mins

which and whereis for commands in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Command Locator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:00remaining
Output of which command
What is the output of the command which ls on a typical Linux system?
Linux CLI
which ls
A/bin/ls
Bls: command not found
C/usr/bin/which
D/usr/local/bin/ls
Attempts:
2 left
💡 Hint
The which command shows the full path of the executable that runs when you type a command.
💻 Command Output
intermediate
1:00remaining
Output of whereis command
What does the command whereis python3 typically output?
Linux CLI
whereis python3
Apython3: command not found
Bpython3: /usr/bin/python3 /usr/lib/python3 /usr/share/man/man1/python3.1.gz
C/bin/python3
D/usr/local/bin/python3
Attempts:
2 left
💡 Hint
The whereis command shows locations of the binary, source, and manual files.
🧠 Conceptual
advanced
1:30remaining
Difference between which and whereis
Which statement correctly describes the difference between which and whereis commands?
A<code>which</code> shows source code location; <code>whereis</code> shows only the executable path.
B<code>which</code> searches all system directories; <code>whereis</code> only searches the current directory.
C<code>which</code> shows the path of the executable found in PATH; <code>whereis</code> shows locations of binary, source, and man files.
D<code>which</code> and <code>whereis</code> are identical and interchangeable.
Attempts:
2 left
💡 Hint
Think about what each command searches for and where.
🔧 Debug
advanced
1:30remaining
Why does which fail to find a command?
You run which myscript but get no output, even though myscript runs fine when you type it. Why?
AThe script is not in any directory listed in the PATH environment variable.
BThe script has no execute permission.
CThe which command is broken and needs reinstalling.
DThe script is a shell alias or function, not an executable file.
Attempts:
2 left
💡 Hint
Think about what which can find and what it cannot.
🚀 Application
expert
2:00remaining
Using which and whereis in a script
You want a script to check if the git command is installed and print its path. Which snippet correctly does this?
Aif which git > /dev/null; then echo "Git found"; else echo "Git not found"; fi
Bif path=$(which git); then echo "Git found at $path"; else echo "Git not found"; fi
Cif [ $(which git) ]; then echo "Git found"; else echo "Git not found"; fi
Dif whereis git; then echo "Git found"; else echo "Git not found"; fi
Attempts:
2 left
💡 Hint
Think about how to check command success and suppress output.