Sobes.tech
Junior — Middle

Can you explain the working principle and main functions of the grep command in Linux?

sobes.tech AI

Answer from AI

The grep command in Linux is used to search for lines in files or the output of other commands that match a specified pattern (usually a regular expression). Main functions:

  • Search for text by pattern in files
  • Filter output of other commands
  • Support for regular expressions
  • Options to ignore case, display line numbers, count matches

Example of usage:

grep -i "error" /var/log/syslog

This example searches for all lines containing "error" regardless of case, in the system log.