How do I "ls -R | cat | grep print" ?
![](https://lemmy.world/pictrs/image/692dc450-da28-4b28-877f-43a5a3ce516e.jpeg)
![](https://lemmy.world/pictrs/image/0943eca5-c4c2-4d65-acc2-7e220598f99e.png)
Hi friends! 🤓 I am on a gnulinux and trying to list all files in the active directory and it's subdirectories. I then want to pipe the output to "cat". I want to pipe the output from cat into grep.
Please help! 😅
You are viewing a single comment
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: https://en.m.wikipedia.org/wiki/Glob_(programming). Technically yourls
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 (thefind
commands listed would also find the hidden files).EDIT: Should have mentioned that
-R
is also recursive, but will follow symlinks, where-r
will ignore them.TIL