010-100 · Question #64
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. This question tests knowledge of the Linux 'find' command for recursively locating a file by name starting from the current directory.
Question
How can the current directory and its subdirectories be searched for the file named MyFile.xml?
Options
- Afind . -name MyFile.xml
- Bgrep MyFile.xml | find
- Cgrep -r MyFile.xml .
- Dless MyFile.xml
- Esearch Myfile.xml ./
How the community answered
(57 responses)- A84% (48)
- B2% (1)
- C2% (1)
- D7% (4)
- E5% (3)
Why each option
This question tests knowledge of the Linux 'find' command for recursively locating a file by name starting from the current directory.
The command 'find . -name MyFile.xml' uses the 'find' utility with '.' as the starting path (current directory) and the '-name' predicate to match files by exact filename. The find command traverses all subdirectories recursively by default, making this the correct and standard approach.
This is invalid syntax - grep searches file contents for text patterns and cannot be piped into find in this form to locate files by name.
'grep -r MyFile.xml .' recursively searches inside files for the text string 'MyFile.xml', not for a file whose name is MyFile.xml.
'less MyFile.xml' opens a known file path in a pager for viewing its contents and performs no directory search.
'search' is not a standard Linux command and this syntax would produce a command-not-found error on a typical Linux system.
Concept tested: Linux find command recursive file name search
Source: https://www.gnu.org/software/findutils/manual/html_mono/find.html
Topics
Community Discussion
No community discussion yet for this question.