nerdexam
LPI

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.

Finding Your Way on a Linux System

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

(55 responses)
  • A
    89% (49)
  • C
    5% (3)
  • D
    4% (2)
  • E
    2% (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.

Afind . -name MyFile.xmlCorrect

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.

Bgrep MyFile.xml | find

grep searches file contents for text patterns, not filenames; piping to find with no arguments is also invalid syntax.

Cgrep -r MyFile.xml.

grep -r searches inside files recursively for the string 'MyFile.xml' as content, not for a file bearing that name.

Dless MyFile.xml

less is a terminal pager for viewing the contents of a known file; it does not traverse the filesystem looking for files by name.

Esearch MyFile.xml ./

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

#find command#file search#directory traversal

Community Discussion

No community discussion yet for this question.

Full 010-160 Practice