A recent thread titled "Get a list of files that contain a string"
produced an answer suggesting the OP use "grep -rl regexp" with "-l
string" being the GNU grep option to only output the file name when
"regexp" matches a string in a file, and "-r" being the GNU grep option
to recursively find files.
I'm trying to understand why it's OK for GNU grep to have options to
find files:
-d, --directories=ACTION how to handle directories;
-r, --recursive like --directories=recurse
-R, --dereference-recursive likewise, but follow all symlinks
--include=GLOB search only files that match GLOB (a file
pattern)
--exclude=GLOB skip files that match GLOB
--exclude-from=FILE skip files that match any file pattern from
FILE
--exclude-dir=GLOB skip directories that match GLOB
when traditionally "grep" exists to "g/re/p" (the "ed" commands to
Globally match a Regular Expression within files and Print the result),
the tool "find" exists to "find" files, no other text processing
commands have options to find files, and #1 in the Unix philosophy
(
https://en.wikipedia.org/wiki/Unix_philosophy) is to "Make each program
do one thing well. To do a new job, build afresh rather than complicate
old programs by adding new "features"."
If grep should have options to find files then maybe they should also:
a) Give "grep" additional options to "sort" it's output, "tr"anslate
characters, "paste" results from multiple files, etc.
b) Give "sed", "awk", "tr", "cut", "paste" etc. the same options as GNU
grep now has so they can also "find" files.
I see grep commands these days that are a relatively long, complicated
mixture of options, some to find files and others to search within
files, e.g.:
grep -r --include='*.html' --include='*.php' --include='*.htm' -Fxl
'regexp' /some/path/
grep -R --include='*.{html,php,htm}' -Fxl 'regexp' /some/path
when "find ... -exec grep ... {} +":
find /some/path \( -name '*.html' -o -name '*.php' -o -name '*.htm'
\) -exec grep -Fxl 'regexp' {} +
find /some/path -regextype egrep -regex '.*\.(html|php|htm)$' -exec
grep -Fxl 'regexp' {} +
or similar would do the job about as briefly and efficiently as well as
making it easier to replace just the grep command with sed or awk
if/when the "search within files" part in future became more complex
than made sense for "grep".
So:
1) Is there some reason why the GNU folks having added options to find
files onto grep was a reasonable thing to do rather than flying in the
face of the Unix philosophy and unnecessarily complicating the interface
of grep?
2) Can we expect GUN grep to get additional options in future to do
other things that other Unix commands currently do?
3) Can we expect GNU sed, awk, etc. to also get options to find files
for consistency with GNU grep?
Ed.