Linux Administration
medium

Questão de Linux Administration #019e3987

Enunciado da Questão
Linux Administration
#whereis
#man-pages
#binary-location
#file-search
#coreutils
Médio

Which of the following commands can be used to locate programs and their corresponding man pages and configuration files?

A

dirname

B

which

C

basename

D

query

E

whereis

Correta

Explicação Oficial / Explicações da Comunidade

The whereis command is specifically designed to locate binary executables, source code, and manual page files for a given program. It searches in standard system directories (e.g., /bin, /sbin, /usr/bin, /usr/share/man) and displays the paths to the binary, man page, and configuration files if they exist. For example, whereis ls returns output like ls: /bin/ls /usr/share/man/man1/ls.1.gz.

How it Works

whereis uses a hardcoded list of directories (typically defined in the WHEREIS environment variable or compiled defaults) to search for files. It does not rely on a database like locate; instead, it performs a filesystem search in common locations. The command supports flags such as -b (binaries only), -m (man pages only), and -s (source code only).

Why the Correct Value is Right

The whereis command is the only option that can locate both programs and their corresponding man pages and configuration files. It is a standard utility on Unix-like systems and is part of the GNU coreutils.

Why the Incorrect Values are Wrong

  • dirname extracts the directory path from a given file path (e.g., dirname /usr/bin/ls returns /usr/bin). It does not search for programs or man pages.
  • which locates the executable file associated with a command by searching the user's $PATH. It only shows the binary, not man pages or configuration files.
  • basename strips directory and suffix from a file path (e.g., basename /usr/bin/ls returns ls). It does not perform any searching.
  • query is not a standard Linux command for locating programs or documentation. It may be used in specific contexts (e.g., RPM package queries with rpm -q), but it does not serve the general purpose described in the question.