Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Recursively grep while specifying sub directory

I have a directory structure that looks something like this:

/home/states/Alabama
/home/states/Alaska
/home/states/Arizona

Within each state subdirectory, I have several more sub directories that look something like:

/home/states/Alabama/drink
/home/states/Alabama/food
/home/states/Alabama/fun

I want to grep for a keyword and my command looks like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

grep -R "string" –include=*.cfg *

How can I specify the subdirectory within a state, so I only want to grep within the food directory within each state?

>Solution :

Use a wildcard to specify the path:

grep -R 'string' /home/states/*/food/*.cfg
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading