GSEC · Question #235
You work as a Network Administrator for Perfect Solutions Inc. The company has a Linux-based network. You are required to search for the error messages in the /var/log/messages log file. Which of…
The correct answer is C. cat /var/log/messages | grep error. Piping cat output into grep filters the log file to display only lines containing the search term, making it the correct way to find error messages.
Question
You work as a Network Administrator for Perfect Solutions Inc. The company has a Linux-based network. You are required to search for the error messages in the /var/log/messages log file. Which of the following commands will you use to accomplish this?
Options
- Aps /var/log/messages
- Bcat /var/log/messages | look error
- Ccat /var/log/messages | grep error
- Dcat /var/log/messages
How the community answered
(31 responses)- A6% (2)
- B3% (1)
- C77% (24)
- D13% (4)
Why each option
Piping cat output into grep filters the log file to display only lines containing the search term, making it the correct way to find error messages.
The ps command displays currently running processes and cannot read or search file contents.
The look command performs prefix-based searching in sorted word files and is not designed for filtering arbitrary log file content.
The command cat /var/log/messages | grep error sends the full file contents through a pipe to grep, which filters and returns only the lines containing the string 'error'. This is the standard Linux pattern for searching plain-text log files for specific keywords, and grep supports regex patterns for more advanced filtering.
cat /var/log/messages alone outputs the entire file with no filtering, so error messages would not be isolated from the rest of the output.
Concept tested: Linux grep command for searching log files
Source: https://man7.org/linux/man-pages/man1/grep.1.html
Topics
Community Discussion
No community discussion yet for this question.