How To Search Multiple Files Using GREP

Written by Santosh Prasad

If you want to check all the files in directory for specific entry this article will help you to find the file. Suppose you have two web server and you take backup of all web code when ever developer do some changes to web file. You store all the backup in one folder. If you want to check which file developers changed particular file. Using below command you can grep all the files at a time, instead of greping/searching file by file.

For example, my backup file location is /data/code-bkp/.

# grep -n ‘array’ /data/code-bkp/*


-n :- Numbering the lines in that files which contain “array”.

You can also use -l option to just list where your “array” word contains like below.

# grep -l ‘array’ /data/code-bkp/*

Other way if you want to search also sub-directory, you can use -r option like below.

# grep -rn ‘array’ /data/code-bkp/*

If you have any other option please share with us.


About the author


Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment