Computer Hope

Software => BSD, Linux, and Unix => Topic started by: balasahu on May 04, 2021, 05:20:40 AM

Title: How do I recursively grep all directories and subdirectories?
Post by: balasahu on May 04, 2021, 05:20:40 AM

How do I recursively grep all directories and subdirectories?

Code: [Select]
find . | xargs grep "texthere" *
Thanks.
Title: Re: How do I recursively grep all directories and subdirectories?
Post by: nil on May 04, 2021, 03:26:12 PM
No need for xargs - you can use the grep -r option:

Code: [Select]
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 (https://www.computerhope.com/unix/ugrep.htm#examples)