Which command searches for the string 'error' recursively under /var/log with case-insensitive matching and line numbers?

Prepare for the Red Hat Certified Systems Admin Exam EX200. Enhance your skills with interactive quizzes, flashcards, and detailed explanations. Ace your certification exam today!

Multiple Choice

Which command searches for the string 'error' recursively under /var/log with case-insensitive matching and line numbers?

Explanation:
To find matches across a directory tree with case-insensitive handling and include line numbers, you use grep with multiple options combined before the path you’re searching. The best command uses -R to search recursively, -i to ignore case, and -n to print line numbers, with the pattern "error" and the target path /var/log. This means every file under /var/log, including subdirectories, is scanned, and any line containing error in any case will be shown along with its line number and file name. The quotes around the pattern ensure it’s treated as a single string, which is especially important if the pattern contained spaces or special characters. The other options fail because, for example, one omits the recursive flag and would only search the top-level files in /var/log, not the whole tree; another uses a capitalized pattern without -i, so a lowercase instance of error could be missed; and placing the -R option after the path makes it be treated as an item in the path list rather than as a flag, or simply be ignored.

To find matches across a directory tree with case-insensitive handling and include line numbers, you use grep with multiple options combined before the path you’re searching. The best command uses -R to search recursively, -i to ignore case, and -n to print line numbers, with the pattern "error" and the target path /var/log. This means every file under /var/log, including subdirectories, is scanned, and any line containing error in any case will be shown along with its line number and file name. The quotes around the pattern ensure it’s treated as a single string, which is especially important if the pattern contained spaces or special characters.

The other options fail because, for example, one omits the recursive flag and would only search the top-level files in /var/log, not the whole tree; another uses a capitalized pattern without -i, so a lowercase instance of error could be missed; and placing the -R option after the path makes it be treated as an item in the path list rather than as a flag, or simply be ignored.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy