Tuesday, October 27, 2009

Linux: search pattern in files

If you want to search a string (e.g. "TheString") or a pattern in all the files under the current directory, you know you can use:
        grep TheString *

It will not search the files under the sub-directories.

When I wanted to search all the files under each directories recursively, I don't know why but, I did this:
        find . -type f | xargs grep TheString
        find . -type f -exec grep -H TheString '{}' \;

Until recently I found that I could do much less typing:
        grep -r TheString *

Is it because grep did not have the -r option in the old days?

No comments:

Get This <