Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command output redirect to file and terminal [duplicate]

I am trying to throw command output to file plus console also. This is because i want to keep record of output in file. I am doing following and it appending to file but not printing ls output on terminal.

$ls 2>&1 > /tmp/ls.txt 
like image 725
Satish Avatar asked Nov 27 '12 19:11

Satish


People also ask

Can we redirect the output of a command to a file and display at the same time?

Redirecting output to Multiple files and screen: If you want to redirect the screen output to multiple files, the only thing you have to do is add the file names at the end of the tee command.

How do I copy terminal output to a file?

the shortcut is Ctrl + Shift + S ; it allows the output to be saved as a text file, or as HTML including colors!

What command would you use to duplicate stdout from a program to both stdout and a file?

The tee command, used with a pipe, reads standard input, then writes the output of a program to standard output and simultaneously copies it into the specified file or files. Use the tee command to view your output immediately and at the same time, store it for future use.


1 Answers

Yes, if you redirect the output, it won't appear on the console. Use tee.

ls 2>&1 | tee /tmp/ls.txt 
like image 127
Karoly Horvath Avatar answered Sep 20 '22 15:09

Karoly Horvath