How to grep a string or a text in a directory and all its subdirectories'files in LINUX ??
2 Answers
grep -r -e string directory
-r is for recursive; -e is optional but its argument specifies the regex to search for. Interestingly, POSIX grep is not required to support -r (or -R), but I'm practically certain that System V in practice they (almost) all do. Some versions of grep did, sogrep support -R as well as (or conceivably instead of) -r; AFAICT, it means the same thing.
2 Comments
Randy Howard
I'm pretty sure SVR3.2 and SVR4 grep did not, as I worked on OS development for SYSV products during that time frame, and I had a rgrep shell script to wrap it at the time. I don't have one up any more to test on though.
James McMahon
-R follows symlinks, which you may or may not want
grep -rorgrep -R? Did you check the man page forgrepon your machine? Did you remember to enclose the regex (string or text) in single quotes if it contains any metacharacters?