Linux grep 函数中的最大计数无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5164471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 03:05:10  来源:igfitidea点击:

Invalid max count in grep function

linuxunixfindgrepsystemtime

提问by Some Java Guy

If I do a find . -mmin -1I get 'myfile' which was modified in last one minute.

如果我这样做,find . -mmin -1我会得到在最后一分钟修改过的“myfile”。

But when I want to search a particular string in that file by doing

但是当我想通过执行搜索该文件中的特定字符串时

grep 'myString' myfile -mmin -1 

I get the error invalid max count

我收到错误 invalid max count

I also tried

我也试过

find . -name "myfile" -exec grep 'myString' myfile -mmin -5

I get the error find: missing argument to -exec

我收到错误 find: missing argument to -exec

So my question is How do I grep or cat only the changes within a file which happened in last 5 mins. Now that I know the file name which was modified during that period.

所以我的问题是 How do I grep or cat only the changes within a file which happened in last 5 mins. Now that I know the file name which was modified during that period.

Suggestions? Thanks in adv.

建议?感谢广告。

采纳答案by abesto

Grep doesn't have an mmin argument as far as I can see. It doeshave a -m argument with a number parameter. grep 'myString' myfile -m3will stop after 3 lines containing myString. So, the error message means that 'min' in -mminis not a valid maximum count.

据我所知,Grep 没有 mmin 参数。它确实有一个带有数字参数的 -m 参数。grep 'myString' myfile -m3将在包含 myString 的 3 行后停止。因此,错误消息意味着 'min' in-mmin不是有效的最大计数。

回答by Johan Ur Riise

grep something *

grep东西*

Error:

错误:

grep: invalid max count

grep:最大计数无效

Verify that you have a file with a leading dash in the name in the current directory. The file name might be taken for an option.

验证当前目录中的文件名中是否有前导破折号。文件名可能被用作一个选项。

For example:

例如:

grep something // okay

touch -- -mmin

**grep something **

**grep 东西 **

grep: invalid max count

grep:最大计数无效

Workaround:

解决方法:

**grep -- something **

**grep -- 东西 **

From man getopt:

来自man getopt

Each parameter after a --parameter is always interpreted as a non-option parameter.

参数后的每个参数--始终被解释为非选项参数。