linux shell:为什么零结束行不按预期工作?

时间:2014-11-13 22:35:31

标签: linux shell command-line

我已经读过" man"关于grep,当我尝试" classic"它的工作方式,而当我尝试使用零结束线时,它不起作用:

/cygdrive/g/eb # find . -type f | grep -E 'pdf$'
./Je_vais_mieux.pdf
./La_delicatesse.pdf
./Femme.pdf
./Souvenirs.pdf
/cygdrive/g/eb # find . -type f -print0 | grep -ZE 'pdf$'
Binary file (standard input) matches
/cygdrive/g/eb # find . -type f -print0 | grep -zE 'pdf$'
Binary file (standard input) matches
/cygdrive/g/eb # find . -type f -print0 | grep -ZzE 'pdf$'
Binary file (standard input) matches

我错过了什么?

1 个答案:

答案 0 :(得分:1)

您遗漏grep -a,告诉grep其输入实际上是文字内容:

find . -type f -print0 | grep -E -Zz -a 'pdf$'

那就是说,这是一个愚蠢的事情,因为find可以在没有grep帮助的情况下通过后缀过滤自己的输出:

find . -name '*pdf' -type f -print0