nerdexam
CompTIA

220-1002 · Question #478

A Linux user wants to use the grep command to identify every file name in the current directory that contains the word "mandatory". Which of the following commands would BEST accomplish this?

The correct answer is B. grep -i mandatory *. The command 'grep -i mandatory ' searches all files in the current directory (the wildcard matches all files) for the string 'mandatory' in a case-insensitive manner (the -i flag). Using -i ensures that variations like 'Mandatory' or 'MANDATORY' are also matched, making it the…

Hardware and network troubleshooting

Question

A Linux user wants to use the grep command to identify every file name in the current directory that contains the word "mandatory". Which of the following commands would BEST accomplish this?

Options

  • Agrep -d mandatory *
  • Bgrep -i mandatory *
  • Cgrep mandatory file
  • Dgrep mandatory *

How the community answered

(34 responses)
  • A
    3% (1)
  • B
    88% (30)
  • C
    6% (2)
  • D
    3% (1)

Explanation

The command 'grep -i mandatory *' searches all files in the current directory (the wildcard * matches all files) for the string 'mandatory' in a case-insensitive manner (the -i flag). Using -i ensures that variations like 'Mandatory' or 'MANDATORY' are also matched, making it the most thorough and reliable search. 'grep mandatory *' (choice D) is similar but case-sensitive, potentially missing results. 'grep mandatory file' (choice C) only searches a single file literally named 'file'. 'grep -d mandatory *' uses -d which controls directory handling behavior, not case sensitivity, and is not the right flag for this task.

Topics

#grep command#Linux#case-insensitive search#command line

Community Discussion

No community discussion yet for this question.

Full 220-1002 Practice