nerdexam
LPI

010-150 · Question #65

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 the -name predicate recursively searches a directory tree for files matching a given name.

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

(32 responses)
  • A
    72% (23)
  • B
    3% (1)
  • C
    3% (1)
  • D
    16% (5)
  • E
    6% (2)

Why each option

The find command with the -name predicate recursively searches a directory tree for files matching a given name.

Afind . -name MyFile.xmlCorrect

The command 'find . -name MyFile.xml' begins its search at the current directory (.) and descends into all subdirectories, returning every path whose filename matches MyFile.xml exactly. This is the standard POSIX-compliant method for locating a file by name within a directory tree.

Bgrep MyFile.xml | find

grep searches the contents of files for a text pattern and cannot locate files by name; piping a filename string into find is not valid syntax for this purpose.

Cgrep -r MyFile.xml .

grep -r recursively searches the contents of files for the pattern 'MyFile.xml', not for a file whose name is MyFile.xml.

Dless MyFile.xml

less is a pager for viewing the contents of a known file; it requires the file path as an argument and cannot search for a file by name.

Esearch Myfile.xml ./

'search' is not a standard Linux command and would produce a 'command not found' error on typical systems.

Concept tested: Using find command to locate files by name

Source: https://man7.org/linux/man-pages/man1/find.1.html

Topics

#find command#file search#directory traversal#recursive search

Community Discussion

No community discussion yet for this question.

Full 010-150 Practice