My best shot so far is (for looking for strings in a directory containing a large C program)
find ~/example_directory -type f \( -name "*.mk" -or -name "*.[sch]" \) -print0 | xargs -0 -e grep "example_string"
Which works pretty well, but it relies on all the interesting things being in .mk makefiles, .c or .h source files, and .s assembler files.
I was thinking of adding in things like 'all files called Makefile' or 'all *.py python scripts', but it occurs that it would be way easier if there were some way to tell find only to find the text files.
If you just run grep on all files, it takes ages, and you get lots of uninteresting hits on object files.
GNU grep supports the -I
option, which makes it treat binary files (as determined by looking at the first few bytes) as if they don't match, so they are essentially skipped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With