In Windows, I would have done a search for finding a word inside a folder. Similarly, I want to know if a specific word occurs inside a directory containing many sub-directo
Similar to the answer posted by @eLRuLL, a easier way to specify a search that respects word boundaries is to use the -w
option:
grep -wnr "yourString" .
Why not do a recursive search to find all instances in sub directories:
grep -r 'text' *
This works like a charm.
grep -nr 'yourString*' .
The dot at the end searches the current directory. Meaning for each parameter:
-n Show relative line number in the file
'yourString*' String for search, followed by a wildcard character
-r Recursively search subdirectories listed
. Directory for search (current directory)
grep -nr 'MobileAppSer*' .
(Would find MobileAppServlet.java
or MobileAppServlet.class
or MobileAppServlet.txt
; 'MobileAppASer*.*'
is another way to do the same thing.)
To check more parameters use man grep command.
grep -r "yourstring" *
Will find "yourstring" in any files and folders Now if you want to look for two different strings at the same time you can always use option E and add words for the search. example after the break
grep -rE "yourstring|yourotherstring|$" *
will search for list locations where yourstring
or yourotherstring
matchesDon't use grep. Download Silver Searcher or ripgrep. They're both outstanding, and way faster than grep or ack with tons of options.
The following sample looks recursively for your search string
in the *.xml
and *.js
files located somewhere inside the folders path1
, path2
and path3
.
grep -r --include=*.xml --include=*.js "your search string" path1 path2 path3
So you can search in a subset of the files for many directories, just providing the paths at the end.