The task requires a command that meets several criteria:
Recursive search: This is provided by the -r or -R option.
Show line numbers: The -n option adds line numbers to the output.
Display the filename: When performing a recursive search, grep automatically prefixes each match with the file path; no extra option is needed.
Suppress error messages: The -s (or --no-messages) option suppresses errors for unreadable files.
The only answer that combines all the necessary options is grep -Rns "PermitRootLogin" /etc. The options -R, -n, and -s can be combined as -Rns (or -rns).
Why the distractors are wrong:
grep -rql "PermitRootLogin" /etc uses -q (quiet) and -l (list files), which prevents it from printing the matching lines and their line numbers.
grep -Rin "PermitRootLogin" /etc is missing the -s option, so it will still display "Permission denied" errors.
grep -r "PermitRootLogin" /etc 2>/dev/null successfully suppresses error messages by redirecting stderr, but it lacks the -n option to display line numbers.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the grep command do in Linux?
Open an interactive chat with Bash
What is the purpose of the -R and -r options in grep?
Open an interactive chat with Bash
What happens if a file is unreadable during a grep search?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
System Management
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access