search through all *.py files
9,942
Try this,
find / -name '*.py' -exec grep -l "keyword" {} \;
Explanation:
find / -name '*.py'
: Find files below/
withpy
extension.-exec grep -l keyword {} \;
Within the files found,grep
for keyword and output the filename instead of the match-l
.
I'm not familiar with Mac OS, but if you have globstar
option in your shell, you can use the following:
shopt -s globstar
grep -l keyword /**/*.py
Related videos on Youtube
Author by
Joe
Updated on September 18, 2022Comments
-
Joe over 1 year
I am using Mac OS terminal (similar to Linux) and trying to find best way to search inside all files on a computer that has extension *.py
What is the best way to achieve this?
I wanted to put 1 keyword for search and quickly show the whole path of these python files are that contain requested keyword in them..
-
ctrl-alt-delor over 5 yearsI think mac has
bash
shell (same as Gnu/Linux), but by default not all gnu tools (some are bsd). Yourfind
finds files ending.py
(there is no such thing as file-name-extensions, on Unix).