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:
- find . -name MyFile.xml
Explanation:
Command:
find . -name MyFile.xml.(dot): Specifies the current directory as the starting point for the search.-name: Tellsfindto 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:
grep -r MyFile.xml .:grepis 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.
search MyFile.xml ./:searchis not a standard command in Linux, so this command would result in an error.
grep MyFile.xml | find:This command uses
grepto look for the text "MyFile.xml" in standard input but doesn’t perform the intended search for files namedMyFile.xml.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
