You are on page 1of 1

Grep Commands

1.Search for the given string in a file

grep "string" filename

2. Checking for the given string in multiple files

grep "string" file_pattern

3. Case insensitive search

grep -i "string" file_name

4. Match regular expression in files

grep "regexp" file_name

5. Checking for full-words not for substring

grep -w "word" file_name

6. Recursive searching

grep -r "string" *

7. Exclude pattern match

grep -v "string" file_name

8. Counting the number of matches

grep -c "string" file_name

9.To display the file names that matches the pattern

grep -l "string" file_pattern

10. Show only matched string

grep -o "regexp" file_name

11. Shows line number while displaying the output

grep -n "string" file_name

You might also like