Search

Wednesday 18 April 2012

How to use the GREP command


I recently had to search for a particular string in a bunch of PHP and CGI bin files, other search methods would not have worked so grep came to the rescue!

grep command
grep “text string to search” directory-path

Examples

To search for a string called CHEESE in all text files located in /home/purpleotter/*.txt directory:


$ grep "CHEESE" /home/purpleotter/*.txt

To search all subdirectories recursively

To search for a text string in all files under directories, recursively use the -r option:

$ grep -r "CHEESE" /home/purpleotter