medium
Single Answer
0Nathan needs to know how many times an event occurred and wants to check a log file for that event. Which of the following grep commands will tell him how many times the event happened if each occurrence is logged independently in the logfile.txt log file, and uses a unique event ID, event101?
Answer Options
A
grep logfile.txt -n 'event101'
B
grep -c 'event101' logfile.txt
C
grep logfile.txt -c 'event101'
D
grep -c event101 -i logfile.txt
Correct Answer: B
Explanation
The - c flag for grep counts the number of occurrences for a given string in a file. The - n flag shows the matched lines and line numbers. Even if you’re not sure about which flag is which, the syntax should help on a question like this. When using grep, the pattern comes before the filename, allowing you to rule out two of the options right away.