Linux Grep Command: Find Files with 'mandatory' in Current Directory

Using the grep command to identify file names in the current directory containing the word 'mandatory' in Linux.

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?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

B.

The correct answer is D. grep mandatory *.

Explanation:

grep is a command-line utility for searching through text data. It is commonly used in Linux and other Unix-like operating systems.

The command grep mandatory * searches for the word "mandatory" in all files in the current directory (represented by the * character, which is a wildcard that matches any filename). This command will print out all lines in all files that contain the word "mandatory", along with the filename and line number.

Option A (grep "d mandatory *) is incorrect because it is missing a quote after the letter "d". This could result in a syntax error.

Option B (grep "i mandatory *) is incorrect because the "i" option specifies a case-insensitive search, which is not necessary for this question. Additionally, the command is missing a closing quote after the wildcard character.

Option C (grep mandatory file) is incorrect because it is looking for the word "mandatory" in a file named "file", rather than searching for the word in all files in the current directory.

Therefore, the BEST command for the Linux user to use is D. grep mandatory *.