grep searches for a pattern inside a file and prints every line that
matches.
grep pattern file
grep root /etc/passwd
That prints every line of /etc/passwd containing the word "root".
Usually more than one line comes back, because "root" appears in system
paths too.
-i - case insensitive. Matches "Error", "ERROR", "error" the same.-n - show the line number for each match.-c - just count matches, don't print them.-v - invert. Print lines that do NOT match.grep -in error /var/log/syslog # case insensitive, with line numbers
grep -c nologin /etc/passwd # how many accounts can't log in
grep -v '^#' /etc/hosts # skip comment lines
That last one is a habit worth stealing:
grep -v '^#' /etc/hosts
strips comments from any config file, leaving you with just the settings that actually apply.