grep command is used to search for a word or character steam in files. We can use grep to search for multiple files with in a given directory by using below command
grep ‘search-term’ *
Where * will be replaced by each file in a given directory by your Shell.
But is it possible to search with in subdirectories as well?
Yes, we can do that by using grep -r(for recoursely) and -l (for listing files) as shown below.
grep -rl “searchterm” foldername
Example: I want to search for ‘abc’ in all the files in present working directory as well as sub directories, I used below command.
grep -rl for .
hope this helps when search sub directories.
Latest posts by Surendra Anne (see all)
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018
- wget download a file to a directory in Linux/Unix - June 4, 2018
- GIT: How to compare two GIT branches? - June 3, 2018
- Online training on Linux Bash shell scripting - February 8, 2018