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

Linux search subdirectories and among .js .py files for a specific keyword

I am trying to search for the file/script with a specific keyword in all the sub-directories beginning from the root or home directory. My search yielded so many files, but I want to search only .js, .py types. I want to know the file name containing this matching word.

grep -name '*.js' -rl "matching word" ./

present output:

grep: invalid max count

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

>Solution :

Here is one way:

find start_dir -type f \( -name "*.js" -o -name "*.py" \) -exec grep -l "word" {} \;

It will find all .js or .py files in or under the start directory and then grep them for the given word. There’s other ways, but this is my "go to" for this type of thing.

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