grep - r不可用;现在该做什么?

时间:2022-02-20 09:20:54

I am trying to search recursively for a string in all files contained in the current folder, where I am executing grep. But it seems that grep on this host is too old. Here are some usages of it.

我正在尝试递归地搜索当前文件夹中包含的所有文件中的字符串,我正在执行grep。但似乎这个节目主持人的grep太老了。这里有一些用法。

>> grep -r "some string here" *.*
grep: illegal option -- r
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvwx] -e pattern_list...
        [-f pattern_file...] [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvwx] [-e pattern_list...]
        -f pattern_file... [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvwx] pattern [file...]

So how should I do what I want?

那我该怎么做呢?

1 个解决方案

#1


8  

Assuming you have find,

假设您已经找到,

find . -type f -exec grep "some string here" {} \;

Notice also that your wildcard would only match files whose name contained a dot; I assume that was a mistake, but if not, add -name '*.*' before -exec (or change the find . to find *.* if you meant to search directories whose name contains a dot, which is what your grep command would actually do).

还要注意,您的通配符只匹配名称包含一个点的文件;我认为这是一个错误,但如果没有,就加上-name '*。*“在-exec之前(或更改发现)。找到*。*如果你想搜索名字包含一个点的目录,这就是你的grep命令所要做的。

The old DOS 8+3 wildcard *.* would match all files because the dot was implicit even in file names which didn't have an extension. The Unix wildcard for all files (which do not start with a dot) is simply *.

旧的DOS 8+3通配符*。*将匹配所有的文件,因为即使在没有扩展名的文件名中,点也是隐式的。所有文件的Unix通配符(不以一个点开始)是简单的*。

This could be made a bit more efficient with xargs or with a newer find which supports -exec ... +

通过xargs或支持-exec的新find,可以提高效率。+

#1


8  

Assuming you have find,

假设您已经找到,

find . -type f -exec grep "some string here" {} \;

Notice also that your wildcard would only match files whose name contained a dot; I assume that was a mistake, but if not, add -name '*.*' before -exec (or change the find . to find *.* if you meant to search directories whose name contains a dot, which is what your grep command would actually do).

还要注意,您的通配符只匹配名称包含一个点的文件;我认为这是一个错误,但如果没有,就加上-name '*。*“在-exec之前(或更改发现)。找到*。*如果你想搜索名字包含一个点的目录,这就是你的grep命令所要做的。

The old DOS 8+3 wildcard *.* would match all files because the dot was implicit even in file names which didn't have an extension. The Unix wildcard for all files (which do not start with a dot) is simply *.

旧的DOS 8+3通配符*。*将匹配所有的文件,因为即使在没有扩展名的文件名中,点也是隐式的。所有文件的Unix通配符(不以一个点开始)是简单的*。

This could be made a bit more efficient with xargs or with a newer find which supports -exec ... +

通过xargs或支持-exec的新find,可以提高效率。+