Red Hat Certified System Administrator RHCSA · Free Practice Question Easy

Question 26

How can the current directory and its subdirectories be searched for a file named MyFile.xml?

  • A

    grep -r MyFile.xml .

  • B

    find . -name MyFile.xml

  • C

    search Myfile.xml ./

  • D

    grep MyFile.xml | find

Reveal correct answer

Correct answer: B

Explanation

The correct command to search for a file named MyFile.xml in the current directory and all its subdirectories is:

Explanation:

  • Command: find . -name MyFile.xml

    • . (dot): Specifies the current directory as the starting point for the search.

    • -name: Tells find to look for files matching the specified name.

    • MyFile.xml: The name of the file we are searching for.

This command will output the paths of any files named MyFile.xml located in the current directory or any of its subdirectories.

Why Other Commands are Incorrect:

  1. grep -r MyFile.xml .:

    • grep is used to search within files for a specific text pattern. Here, it would search inside files for the text "MyFile.xml" rather than for files with that name.

  2. search MyFile.xml ./:

    • search is not a standard command in Linux, so this command would result in an error.

  3. grep MyFile.xml | find:

    • This command uses grep to look for the text "MyFile.xml" in standard input but doesn’t perform the intended search for files named MyFile.xml.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need