Thursday, May 19, 2016

Copy command output data to standard output and to a file

Use the tee command: 
 
$ [COMMAND] | tee [OUTPUT.FILE]
 
Where:
 
[COMMAND] is the command you want to execute.
[OUTPUT.FILE] is the file you want to write in.
 
 
Variation for writing the standard error output:
 
$ [COMMAND] 2>&1 | tee [OUTPUT.FILE]
 
Where:
 
[COMMAND] is the command you want to execute. 
[OUTPUT.FILE] is the file you want to write in.
2>&1 redirects stderr(2) to stdout(1).
 
Notes:
2>&1 is different that 2>1.
2>1 means writing to a file with name 1 and 2>&1 means write to the standard output.

0 comments:

Post a Comment

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

Search This Blog

Powered by Blogger.