Wednesday, July 16, 2008

Search Using Grep

1. grep -r "keyword" .
here we are searching for the word "keyword" , in current directory and sub-directories.
This will return the list of files and lines which contain this word.
2. grep -lr "modules" .
This will return only list of files .
3. grep -lr "mod.*" .
grep also supports regular expressions

General tag : grep "options" "keyword" "drive specification"

Where options are:

-a All disks.
-c Show the matched characters in Colour.
-f List the File name.
-h Hard disks only.
-i Make the pattern case Insensitive.
-n List the line Number.
-o Only list the file name.
-s Subdirectories.
-x List the lines which do NOT have the pattern in them.

There are many more options , to explore use:
grep man

No comments: