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)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix- June 29, 2020
- FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- 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