如何在标准输出上显示 Linux 命令的输出并将其通过管道传输到另一个命令? [英] How to display the output of a Linux command on stdout and also pipe it to another command?
本文介绍了如何在标准输出上显示 Linux 命令的输出并将其通过管道传输到另一个命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
如何管道标准输出,同时保持在屏幕上?(而不是输出文件)
例如我要运行命令:
ls -l
然后我有输出到标准输出:
Then I have the output to stdout:
drwxr-xr-x 2 user user 4096 Apr 12 12:34 Desktop
-rw-rw-r-- 1 user user 1234 Apr 12 00:00 file
我想将此输出重定向到另一个命令以进行进一步处理(例如重定向到head -1"以提取第一行).我可以只用一行吗?
And I want to redirect this output to another command for some further processing (like redirecting to 'head -1' to extract first line). Can I do it in just one line?
推荐答案
是的,tee 可以.比如:
Yes, tee will work. Something like:
ls -l | tee | head -1
要将输出附加到文件:
ls -l | tee -a output.txt
这篇关于如何在标准输出上显示 Linux 命令的输出并将其通过管道传输到另一个命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文