Grep In Linux
In this video we will learn how to use the grep command. First example I search for my name in the file names.txt:
grep donald names.txt
To search for whole words, we will use the -w option for example:
grep -w "donald smouse" names.txt
You would put the string in qutoes if it contains spaces or other characters as well.
To do a case sensitive search we would use the -i with grep, for example:
grep -i donald names.txt
To only search for the string only in text files we would:
grep -i donald *.txt(you don't have to use an option when searching only txt files, just *.txt for example grep donald *.txt)
to do a recursive search regardless of extension we would:
grep -r Donald .
Combining flags to do a search for example:
grep -ir Donald . (this would do a case sensitive as well as a recursive search in the /home/cyberguy folder)
You don't have to search within your home directory alone, you can search for anything anywhere!!!
If you wanted to add line numbers to the output we would:
grep -n Donald names.txt
If you wanted to highlight the keyword output we would:
sudo grep --color cyberguy /var/log, and the output would be highlighted(my example on my machine cyberguy is in red color)
If you would like to help support my channel it would be appreciated: patreon.com/cyberguy
Ending Music Provided By: bensound.com
Business Inquiries: donaldsmouse0@gmail.com
27407562 Bytes