Skip to main content
Linux AdministrationMediumSingle Choice

Linux Administration Question

Statement

Which of the following commands can be used to search for the executable file foo when it has been placed in a directory not included in $PATH?

#find#executable-search#path-independent#file-location#filesystem-traversal
A

apropos

B

which

C

find

Correct
D

query

E

whereis

Resolution & Explanations

The find command is used to search for files and directories in a directory hierarchy. It can locate the executable file foo even if it is not in the directories listed in the $PATH environment variable, because find searches based on pathnames and criteria, not the $PATH.

How it Works

find traverses the filesystem starting from a given directory (e.g., /) and matches files based on specified conditions. To find an executable named foo, you can use:

find / -name foo -type f -executable

This searches the entire filesystem for a regular file (-type f) named foo that has the executable permission set (-executable). The -name option matches the filename exactly. Unlike which or whereis, find does not rely on $PATH; it scans the actual filesystem.

Why the Correct Answer is Right

The find command is the correct tool because it can locate files anywhere on the system, regardless of $PATH. It is designed for flexible file searches based on name, type, permissions, and other attributes.

Why the Incorrect Options are Wrong

  • apropos: Searches the manual page names and descriptions for a keyword. It does not locate executable files; it finds relevant man pages.
  • which: Shows the full path of a command by searching the directories listed in $PATH. If foo is in a directory not in $PATH, which will not find it.
  • query: This is not a standard Linux command for file searching. It might be confused with locate or slocate, but query itself is not a valid command.
  • whereis: Locates the binary, source, and manual page files for a command, but it searches only a predefined set of directories (typically /bin, /sbin, /usr/bin, /usr/sbin, and man page directories), not the entire filesystem. It does not search directories outside its default list, so it may miss foo if placed elsewhere.