Possible duplicate:How to connect stdout while keeping it on the screen? (not the output file)
For example, I want to run the command:
ls -l
Then I get the output in 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 further processing (for example, redirecting to "head -1" to extract the first line). Can I do this in only one line?
Yes, the tee will work. Sort of:
ls -l | tee | head -1
To add output to a file:
ls -l | tee -a output.txt
There is a tool called tpipe that allows you to pass a command to two other commands (for example, fork) but is not installed by default on most machines. Using it, your problem will be solved with:
tpipe
ls -l | tpipe head -1