I'm trying to find a way to scan my entire Linux system for all files containing a specific string of text. Just to clarify, I'm looking for text within the file, not in the file name.
When I was looking up how to do this, I came across this solution twice:
find / -type f -exec grep -H 'text-to-find-here' {} \;
However, it doesn't work. It seems to display every single file in the system.
Is this close to the proper way to do it? If not, how should I? This ability to find text strings in files would be extraordinarily useful for some programming projects I'm doing.
.as a single-character wildcard, among others. My advice is to alway use either fgrep or egrep. – Walter Tross Oct 28 '13 at 11:54-Hwith-l(and maybegrepwithfgrep). To exclude files with certain patterns of names you would usefindin a more advanced way. It's worthwile to learn to usefind, though. Justman find. – Walter Tross Oct 28 '13 at 12:01find … -exec <cmd> +is easier to type and faster thanfind … -exec <cmd> \;. It works only if<cmd>accepts any number of file name arguments. The saving in execution time is especially big if<cmd>is slow to start like Python or Ruby scripts. – hagello Jan 28 '16 at 5:16grep "pattern" path/*.txt– fedorqui Dec 2 '16 at 13:13