Skip to content

Instantly share code, notes, and snippets.

@liuxd
Created August 28, 2017 22:51
Show Gist options
  • Save liuxd/f53c9b6ebff30ca2208cd94f967239ce to your computer and use it in GitHub Desktop.
Save liuxd/f53c9b6ebff30ca2208cd94f967239ce to your computer and use it in GitHub Desktop.

现象:

执行以下命令,想要统计当前目录下所有markdown文件的内容行数。

find . -name "*.md"|xargs cat|wc -l

结果报错了:

xargs: unterminated quote

原因

find命令找出的文件名包含了空格,导致这一个报错。

办法

find . -name "*.md" -print0|xargs -0 cat|wc -l

解释

man xargs可以找到以下说明:

-0 Change xargs to expect NUL (``\0'') characters as separators, instead of spaces and newlines. This is expected to be used in concert with the -print0 function in find(1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment