grep:上下文长度参数无效
我想检查iptables规则是否存在(如图所示),但出现以下错误:grep:上下文长度参数无效,grep,Grep,我想检查iptables规则是否存在(如图所示),但出现以下错误: $ sudo iptables-save | grep "-A OUTPUT -p tcp --tcp-flags RST RST -j DROP" grep: OUTPUT -p tcp --tcp-flags RST RST -j DROP: invalid context length argument 也许我要逃避一些角色 问题 grep“-A输出-p tcp--tcp标志RST-j DROP” 对于许多shel
$ sudo iptables-save | grep "-A OUTPUT -p tcp --tcp-flags RST RST -j DROP"
grep: OUTPUT -p tcp --tcp-flags RST RST -j DROP: invalid context length argument
也许我要逃避一些角色 问题
grep“-A输出-p tcp--tcp标志RST-j DROP”
对于许多shell工具,一些参数可能会被错误地解释为标志。根据您的grep版本,以下内容将帮助grep理解“标志”不是真正的标志,而是您正在搜索的表达式的一部分
例如,考虑:
$ echo "-Afoo" | grep "-Afoo"
grep: Invalid argument
解决
用旗帜来划分表达方式
--
标志指示后面没有标志
grep -- "-A OUTPUT -p tcp --tcp-flags RST RST -j DROP"
-e
标志明确标识以下引用的文本作为要搜索的表达式
grep -e "-A OUTPUT -p tcp --tcp-flags RST RST -j DROP"
$ echo "-Afoo" | grep -- "-Afoo"
-Afoo
$ echo "-Afoo" | grep -e "-Afoo"
-Afoo
虽然这些示例是精心设计的,但它们更清楚地说明了问题(和解决方案),并且可以轻松地在没有iptable作为输入文本的系统上进行测试
grep
将-A
视为参数,而不是模式。您需要使用-e“…”
。这很有效,谢谢@如果你把它作为一个答案贴出来,瑞奇可以接受它作为答案。@AnthonyGeoghegan我知道。我也知道这是一个经常出现的问题,我真的不想有另一个答案。我想要一个好的副本,但还没有找到(虽然我刚刚找到)。的副本