So I could use something like grep string -R * to find any occurrence of the string in any files in the folder and sub-folders.
thank you!
Comment on How do I "ls -R | cat | grep print" ?
bjoern_tantau@swg-empire.de 11 months ago
Note, you almost never have to use cat. Just leaving it out would have been enough to find your file (although find is still better).
When you want to find a string in a file it’s also enough to use grep string file
instead of cat file | grep string
. You can even search through multiple files with grep string file1 file2 file*
and grep will tell you in which file the string was found.
So I could use something like grep string -R * to find any occurrence of the string in any files in the folder and sub-folders.
thank you!
grep -r string .
The flag should go before the pattern.
-r
to search recursively, .
refers to the current directory.
Why use .
instead of *
? Because on it’s own, *
will (typically) not match hidden files. See the last paragraph of the ‘Origin’ section of: en.m.wikipedia.org/wiki/Glob_(programming). Technically your ls
command (lacking the -a
) flag would also skip hidden files, but since your comment mentions finding the string in ‘any files,’ I figured hidden files should also be covered (the find
commands listed would also find the hidden files).
litchralee@sh.itjust.works 11 months ago
Obligatory link to the Useless Use of Cat Awards
FuglyDuck@lemmy.world 11 months ago
for a moment, I thought OP was looking for cat photos or something.