010-160 · Question #62
How can the current directory and its subdirectories be searched for the file named MyFile.xml?
The correct answer is A. find . -name MyFile.xml. The find command with a starting path of dot and the -name predicate recursively locates files by filename in the current directory tree.
Question
Options
- Afind . -name MyFile.xml
- Bgrep MyFile.xml | find
- Cgrep -r MyFile.xml.
- Dless MyFile.xml
- Esearch MyFile.xml ./
How the community answered
(55 responses)- A89% (49)
- C5% (3)
- D4% (2)
- E2% (1)
Why each option
The find command with a starting path of dot and the -name predicate recursively locates files by filename in the current directory tree.
find . -name MyFile.xml instructs find to start at the current directory (.) and recursively descend all subdirectories, returning every path whose filename matches MyFile.xml exactly. find is the standard Unix utility for filesystem searches based on name, type, permissions, and other attributes.
grep searches file contents for text patterns, not filenames; piping to find with no arguments is also invalid syntax.
grep -r searches inside files recursively for the string 'MyFile.xml' as content, not for a file bearing that name.
less is a terminal pager for viewing the contents of a known file; it does not traverse the filesystem looking for files by name.
search is not a standard Unix or Linux command; this syntax does not exist in a default shell environment.
Concept tested: Using find to locate files by name recursively
Source: https://www.gnu.org/software/findutils/manual/html_mono/find.html
Topics
Community Discussion
No community discussion yet for this question.