How to grep a string in a directory and all its su

2020-02-16 05:07发布

How to grep a string or a text in a directory and all its subdirectories'files in LINUX ??

2条回答
该账号已被封号
2楼-- · 2020-02-16 06:03
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 grep did, so in practice they (almost) all do. Some versions of grep support -R as well as (or conceivably instead of) -r; AFAICT, it means the same thing.

查看更多
疯言疯语
3楼-- · 2020-02-16 06:06

If your grep supports -R, do:

grep -R 'string' dir/

If not, then use find:

find dir/ -type f -exec grep -H 'string' {} +
查看更多
登录 后发表回答