How do I find all files containing a specific string of text within their file contents? The following doesn’t work. It seems to display every single file in the system. find / -type f -exec grep -H 'text-to-find-here' {} \;
Home/grep
Do the following: grep -rnw '/path/to/somewhere/' -e 'pattern' -r or -R is recursive, -n is line number, and -w stands for match the whole word. -l (lower-case L) can be added to just give the file name of matching files. -e is the pattern used during the search Along with these, --exclude, --includRead more
Do the following:
-r
or-R
is recursive,-n
is line number, and-w
stands for match the whole word.-l
(lower-case L) can be added to just give the file name of matching files.-e
is the pattern used during the searchAlong with these,
--exclude
,--include
,--exclude-dir
flags could be used for efficient searching:--exclude-dir
parameter. For example, this will exclude the dirsdir1/
,dir2/
and all of them matching*.dst/
:This works very well for me, to achieve almost the same purpose like yours.
See less