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
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

grep more stuff at once

Bash
sudo netstat -tulpen | egrep -E "25|587|143|465|993"