我想用命令计算主目录上的所有普通文件:
$ find ~ -type f | xargs echo | wc -w
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option
Run Code Online (Sandbox Code Playgroud)
它提示
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option
Run Code Online (Sandbox Code Playgroud)
使用上有什么问题?
wal*_*tor 13
您的某些文件名似乎在其名称中带有撇号(单引号)。
幸运的是,find并xargs有解决这个办法。find's-print0选项与xargs's-0选项一起生成和使用由NUL( \000) 字符分隔的文件名列表。在Linux的文件名可以包含任何字符,除了NUL和/。
所以,你真正想要的是:
find ~ -type f -print0 | xargs -0 --no-run-if-empty wc -w
Run Code Online (Sandbox Code Playgroud)
阅读man find;man xargs。
| 归档时间: |
|
| 查看次数: |
6988 次 |
| 最近记录: |