010-160 · Question #23
Which of the following commands will search for the file foo.txt under the directory /home?
The correct answer is D. find /home -name foo.txt. The find command uses the -name predicate to search for files by filename, requiring correct syntax with the search path first and the flag immediately preceding the pattern.
Question
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
(31 responses)- C3% (1)
- D94% (29)
- E3% (1)
Why each option
The find command uses the -name predicate to search for files by filename, requiring correct syntax with the search path first and the flag immediately preceding the pattern.
search is not a standard Linux utility for locating files by path; find is the correct command for this purpose.
search is not a valid Linux command, and even a hypothetical search utility would require a flag to specify a filename rather than a bare positional argument.
A space between the hyphen and the word 'file' splits it into two tokens, making '- file' an unrecognized option; additionally, the correct predicate is -name, not -file.
The correct syntax 'find /home -name foo.txt' instructs find to begin traversal at /home and return every file whose name matches foo.txt. The -name predicate performs a case-sensitive filename comparison against each entry encountered during the recursive directory walk.
Without the -name predicate, find interprets foo.txt as an additional starting path to search rather than a filename criterion, resulting in an error or incorrect behavior.
Concept tested: Linux find command -name predicate syntax
Source: https://man7.org/linux/man-pages/man1/find.1.html
Topics
Community Discussion
No community discussion yet for this question.