How to search for a certain word recursively in all files in the current directory and its subdirectories?
I tried to navigate with:
find . | grep "palavra"
How to search for a certain word recursively in all files in the current directory and its subdirectories?
I tried to navigate with:
find . | grep "palavra"
Use the -r
parameter of grep
.
grep -r "foo" .
Where .
indicates the current directory to start the search.
If you prefer to search for a word in files with a specific extension, you can do:
grep -r "foo" ~/*.txt
To ignore warning messages use parameter -s
or --no-messages
:
grep -r -s "foo" ~/*.txt
The output will look similar to this:
~$ grep -r -s "foo" ~/*.txt
/home/user/file1.txt:foo
/home/user/file2.txt:foo
/home/user/file3.txt:foo
~$
You can also use the -exec
option of find
together with grep
. If you need to filter the files with find
then the option below will be faster than grep -r
, because it will not try to search the "word" in all files:
find . -exec grep 'palavra' {} \;
I still think the best could be the
grep -ir "word".
to search for any case sensitive instance
I hope this helps: grep -R "Word" ./