如何在stdout上显示Linux命令的输出并将其传递给另一个命令?

时间:2012-04-12 01:45:38

标签: linux shell command pipe

  

可能重复:
  How to pipe stdout while keeping it on screen ? (and not to a output file)

例如,我想运行命令:

ls -l

然后我输出到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'以提取第一行)。我可以只用一行吗?

2 个答案:

答案 0 :(得分:3)

是的,开球会起作用。类似的东西:

ls -l | tee | head -1

将输出附加到文件:

ls -l | tee -a output.txt

答案 1 :(得分:0)

有一个名为tpipe的工具,它允许您将命令传递给另外两个命令(如fork),但默认情况下它并没有安装在大多数机器上。使用它,您的问题将通过以下方式解决:

ls -l | tpipe head -1
相关问题