Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to redirect a output of a command to two files

Tags:

i need to redirect a output of a command to two files say file1 and file2 file1 is a new file and file2 is already existing file where i need to append the output i have tried

This is not giving the expected results:

command > file1 > file2
like image 256
user75536 Avatar asked Mar 09 '09 09:03

user75536


People also ask

How do you redirect output of command?

The > symbol is used to redirect output by taking the output from the command on the left and passing as input to the file on the right.

How do I redirect content from one file to another?

You can use cat with redirection to append a file to another file. You do this by using the append redirection symbol, ``>>''. To append one file to the end of another, type cat, the file you want to append, then >>, then the file you want to append to, and press <Enter>.

What command will redirect the output of one file to another?

The >> shell command is used to redirect the standard output of the command on the left and append (add) it to the end of the file on the right.

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.


1 Answers

You are looking for the tee command.

$ echo existing >file2
$ date | tee file1 >> file2
$ cat file2
existing
Mon Mar  9 10:40:01 CET 2009
$ cat file1
Mon Mar  9 10:40:01 CET 2009
$
like image 158
phihag Avatar answered Oct 30 '22 03:10

phihag