010-150 · Question #14
How could one search for the file foo.txt under the directory /home?
The correct answer is D. find /home -name foo.txt. The Linux find command searches for files using specific flags; -name is the correct flag to match by filename.
Question
How could one search for the file foo.txt under the directory /home?
Options
- Asearch /home -file foo.txt
- Bsearch /home foo.txt
- Cfind /home -file foo.txt
- Dfind /home -name foo.txt
- Efind /home foo.txt
How the community answered
(57 responses)- A5% (3)
- B2% (1)
- C7% (4)
- D84% (48)
- E2% (1)
Why each option
The Linux `find` command searches for files using specific flags; `-name` is the correct flag to match by filename.
`search` is not a valid Linux command, so this syntax would produce a command not found error.
`search` is not a valid Linux command, and even if it were, no flag is used to specify a filename pattern.
`-file` is not a valid option for the `find` command; the correct option for matching by filename is `-name`.
The `find` command is the standard Linux utility for searching files and directories. The `-name` option specifies a filename pattern to match, making `find /home -name foo.txt` the correct syntax to locate foo.txt under /home recursively.
While `find /home foo.txt` uses the correct command, it omits the required `-name` flag, making it invalid syntax that would produce an error.
Concept tested: Linux find command filename search option
Source: https://man7.org/linux/man-pages/man1/find.1.html
Topics
Community Discussion
No community discussion yet for this question.