grep search pattern command in linux

Here, I have explained about  ‘grep’ command. This command is very use-full for lamp developer. Developers use this command in daily programming life to search the thing into directory.

grep [options] pattern [files]
Options Description
-c : This prints only a count of the lines that match a pattern
-h : Display the matched lines, but do not display the filenames.
-i : Ignores, case for matching
-l : Displays list of a filenames only.
-n : Display the matched lines and their line numbers.
-v : This prints out all the lines that do not matches the pattern
-e exp : Specifies expression with this option. Can use multiple times.
-f file : Takes patterns from file, one per line.
-E : Treats pattern as an extended regular expression (ERE)
-w : Match whole word
-o : Print only the matched parts of a matching line,
 with each such part on a separate output line.
-r: This search recursively.


=> Search a text recursively  into  a directory.

$ grep -r 'search-term'  /path/to/dir

=> Search a text recursively into a pattern of files in a directory.

$ grep -r --include="*.php" "searh-term" /path/to/dir




Leave a Reply

Your email address will not be published. Required fields are marked *