grep string recursively and return line number

To grep a string recursively

grep -rin "string" /directory

Add -w flag for a word search

grep -rinw "string" /directory

Add -l flag to list file name only

grep -rinl "string" /directory

grep only from certain file extensions

grep -rinl "string" /directory --include=*.php

-r recursively

-i ignore-case

-n print line number

-w word search

-l list just the file name

Other options

grep -rnw "searchName" /directory
grep -rnw "searchName" /directory | cut -d : -f 1

Leave a Reply

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

Scroll to top