Bash:如何将一个命令的每个结果传递给另一个命令 [英] Bash: how to pipe each result of one command to another
本文介绍了Bash:如何将一个命令的每个结果传递给另一个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从以下命令返回的所有文件中获得总计行数:
I want to get the total count of the number of lines from all the files returned by the following command:
shell> find . -name *.info
所有.info文件都嵌套在子目录中,所以我不能简单地这样做:
All the .info files are nested in sub-directories so I can't simply do:
shell> wc -l *.info
确定这应该在所有bash用户的曲目中,但会卡住!
Am sure this should be in any bash users repertoire, but am stuck!
谢谢
推荐答案
wc -l `find . -name *.info`
如果只需要总数,请使用
If you just want the total, use
wc -l `find . -name *.info` | tail -1
也可以使用xargs
管道,并且希望可以避免命令行太长".
Piping to xargs
also works, and hopefully can avoid the 'command line too long'.
find . -name *.info | xargs wc -l
这篇关于Bash:如何将一个命令的每个结果传递给另一个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文