nerdexam
GIAC

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.

Linux and Cryptography

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)
  • A
    6% (2)
  • B
    3% (1)
  • C
    77% (24)
  • D
    13% (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.

Aps /var/log/messages

The ps command displays currently running processes and cannot read or search file contents.

Bcat /var/log/messages | look error

The look command performs prefix-based searching in sorted word files and is not designed for filtering arbitrary log file content.

Ccat /var/log/messages | grep errorCorrect

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.

Dcat /var/log/messages

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

#grep#log analysis#Linux commands#/var/log/messages

Community Discussion

No community discussion yet for this question.

Full GSEC Practice