问题
Possible Duplicate:
How to pipe stdout while keeping it on screen ? (and not to a output file)
For example I want to run the command:
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
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?
回答1:
Yes, tee will work. Something like:
ls -l | tee | head -1
To append the output to a file:
ls -l | tee -a output.txt
回答2:
There's a tool called tpipe which allows you to pipe a command to two other commands (like a fork), but it's not installed by default on most machines. Using it, your problem would be solved by:
ls -l | tpipe head -1
来源:https://stackoverflow.com/questions/10116358/how-to-display-the-output-of-a-linux-command-on-stdout-and-also-pipe-it-to-anoth