Bird
Raised Fist0
Linux CLIscripting~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does the which command do in Linux?
easy
A. Lists all files related to a command including source and man pages
B. Displays the manual pages of a command
C. Shows the full path of the executable that runs when you type a command
D. Shows the current directory contents

Solution

  1. Step 1: Understand the purpose of which

    The which command searches your PATH environment to find the executable file that runs when you enter a command.
  2. Step 2: Compare with other options

    whereis lists multiple locations including source and man files, not just the executable path. Manual pages are shown by man. Directory contents are shown by ls.
  3. Final Answer:

    Shows the full path of the executable that runs when you type a command -> Option C
  4. Quick Check:

    which = executable path [OK]
Hint: Remember: which = executable path only [OK]
Common Mistakes:
  • Confusing which with whereis
  • Thinking which shows manual pages
  • Assuming which lists all related files
2. Which of the following is the correct syntax to find the location of the ls command using which?
easy
A. which -l ls
B. which ls
C. which --all ls
D. which ls -a

Solution

  1. Step 1: Recall basic which syntax

    The basic syntax to find the path of a command is simply which command_name. No extra flags are needed for a single path.
  2. Step 2: Analyze options

    Options like -l or --all are not standard or needed for basic usage. Adding -a or extra flags incorrectly after the command name is invalid.
  3. Final Answer:

    which ls -> Option B
  4. Quick Check:

    Simple syntax: which + command [OK]
Hint: Use just 'which command' to find executable path [OK]
Common Mistakes:
  • Adding unnecessary flags to which
  • Placing flags after command name
  • Using incorrect or unsupported options
3. What will be the output of the command whereis bash on a typical Linux system?
medium
A. bash: /bin/bash /usr/share/man/man1/bash.1.gz
B. bash: command not found
C. /usr/bin/bash
D. /bin/bash

Solution

  1. Step 1: Understand whereis output format

    whereis shows multiple locations: the binary executable path, source files if any, and manual page locations.
  2. Step 2: Analyze typical output for bash

    On most systems, whereis bash returns the binary path like /bin/bash and the man page location like /usr/share/man/man1/bash.1.gz.
  3. Final Answer:

    bash: /bin/bash /usr/share/man/man1/bash.1.gz -> Option A
  4. Quick Check:

    whereis = binary + man files [OK]
Hint: whereis shows binary and man page locations [OK]
Common Mistakes:
  • Expecting only one path from whereis
  • Confusing whereis output with which output
  • Thinking whereis returns error if command exists
4. You run which python3 but get no output. What is the most likely reason?
medium
A. Python3 is installed but hidden by a firewall
B. You typed the command incorrectly
C. which command is broken on your system
D. Python3 is not installed or not in your PATH

Solution

  1. Step 1: Interpret empty output from which

    If which returns nothing, it means it did not find the executable in any directory listed in your PATH environment variable.
  2. 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.
  3. Final Answer:

    Python3 is not installed or not in your PATH -> Option D
  4. Quick Check:

    No output from which = command missing or PATH issue [OK]
Hint: No output means command not found in PATH [OK]
Common Mistakes:
  • Assuming which is broken
  • Blaming firewall for missing executable
  • Ignoring PATH environment variable
5. You want to find all locations related to the gcc compiler including binary, source, and manual files. Which command should you use?
hard
A. whereis gcc
B. which gcc
C. locate gcc
D. find / -name gcc

Solution

  1. Step 1: Understand the purpose of each command

    which shows only the executable path. locate searches a database for filenames but may show unrelated files. find searches the entire filesystem but is slow and may produce too many results.
  2. Step 2: Identify the command that shows binary, source, and manual files

    whereis is designed to show all related locations for a command including binary, source, and man pages, making it the best choice.
  3. Final Answer:

    whereis gcc -> Option A
  4. Quick Check:

    whereis = binary + source + man files [OK]
Hint: Use whereis to find all related command files [OK]
Common Mistakes:
  • Using which to find all files
  • Using locate without filtering results
  • Running find without knowing its slowness
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard