There must be a better / shorter way to do this:
# Find files that contain <string-to-find> in current directory
# (including sub directories)
$ find . | xargs grep <string-to-find>
Also, to search only e.g. HTML files:
# find . | grep html$ | xargs grep <string-to-find>
Thanks beforehand!
or, if you want to find files with names matching a regular expression:
or, if you want to search for a regular expression in files with names matching a regular expression
The
grepargument-Houtputs the name of the file, if that’s of interest. If not, you can safely remove it and simply usegrep. This will instructfindto executegrep string-to-find filenamefor each file name it finds, thus avoiding the possibility of the list of arguments being too long, and the need forfindto finish executing before it can pass its results toxargs.To address your examples:
could be replaced with
and
could be replaced with