LFCS · Question #848
An administrator is looking for an executable file foo. Which of the following commands would search for foo within directories set in the shell variable, PATH?
The correct answer is B. which. The which command locates executable files in the directories specified by the shell's PATH environment variable.
Question
Options
- Alocate
- Bwhich
- Cfind
- Dquery
- Ewhereis
How the community answered
(68 responses)- A1% (1)
- B93% (63)
- D1% (1)
- E4% (3)
Why each option
The `which` command locates executable files in the directories specified by the shell's `PATH` environment variable.
`locate` searches a pre-built database of all files on the system, which may not be up-to-date and does not respect the `PATH` variable.
B is correct because the `which` command specifically searches the directories listed in the user's `PATH` environment variable for the executable file specified as an argument. It then prints the full path to the first executable found, indicating which version of the command would be executed.
`find` searches the filesystem based on specified criteria (path, name, permissions, etc.) but does not implicitly use the `PATH` environment variable.
`query` is not a standard Linux command for searching executables in `PATH`.
`whereis` locates source, binary, and man page files for a command, but it searches a predefined set of standard directories, not strictly the `PATH` variable.
Concept tested: Locating executables in PATH
Source: https://man7.org/linux/man-pages/man1/which.1.html
Topics
Community Discussion
No community discussion yet for this question.