Useful Linux grep commands

Grep command is very useful and powerful command to search words in text files. Here is exploitation and some examples:

grep [search word] [place to search] -> global regular expression print. It will print the lines which the [search word] is found in the [place to search]

Search word inside text.txt

grep word text.txt 

Search word inside all the files in the current folder

grep word *

Find whole words only in all files from the current directory

grep -w word *

To search case insensitive

grep -i word *

To search also in the sub-directories

grep -r word *

To search file names

grep -l word *

show 3 lines before and after the find word

grep -n -C 3 word text.txt

Leave a Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.