Skip to content

grep

This command is a must for many roles such as linux system admins, devops ...

Basic

Filter out lines with matching pattern:

Bash
grep pattern somefile.txy

Print only those lines which do not match the pattern (-v option is --invert-match):

Bash
grep -v pattern somefile

Look/Search for content of the files recursively: -i case insensitive; -R recursive;

Bash
grep -Ri somepattern *

Count how many time word appears:

Bash
grep -c RUN Dockerfile

Also grep lines before and after:

Bash
grep pattern -A 20 -B 20 somefile