How do I recursively grep all directories and subdirectories?

Started by balasahu, May 04, 2021, 05:20:40 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

balasahu


How do I recursively grep all directories and subdirectories?

find . | xargs grep "texthere" *

Thanks.

nil

No need for xargs - you can use the grep -r option:


me@nil:~/mydir$ find .
.
./dir4
./dir2
./dir2/file-b.txt
./dir2/dir3
./dir2/dir3/file.txt
me@nil:~/mydir$ grep -r Lorem .
./dir2/file-b.txt:Lorem ipsum dolor amet
./dir2/dir3/file.txt:Lorem ipsum


If you want to follow symlinks, use -R instead.

Examples at Computer Hope - https://www.computerhope.com/unix/ugrep.htm#examples
Do not communicate by sharing memory; instead, share memory by communicating.

--Effective Go