Redirecting output twice

6

1

I want to redirect my output twice from a commandline

For example:

comp.reg $T_GDS_MASTER/bin.new $T_GDS_MASTER/bin.old > $T_GDS/log/comp.reg.out 2>&1

I want that command to also print to the screen. How can I do this?

Malfist

Posted 2011-08-22T19:38:51.063

Reputation: 2 761

Answers

13

The command that you are looking for is tee. The full syntax is here.

soandos

Posted 2011-08-22T19:38:51.063

Reputation: 22 744

1

Have a look at tee - read from standard input and write to standard output and files. script -- make typescript of terminal session -- maybe of interest as well.

Sardathrion - against SE abuse

Posted 2011-08-22T19:38:51.063

Reputation: 390

1

tee is a identity filter, it can output result to stdout and save it:

tee

Redirect output to multiple files, copies standard input to standard 
output and also to any files given as arguments. This is useful when you 
want not only to send some data down a pipe, but also to save a copy.

Syntax
      tee [options]... [file]...

Options
   -a
   --append
        Append standard input to the given files rather than overwriting
        them.

   -i
   --ignore-interrupts'
        Ignore interrupt signals.

Example:

   ps -ax | tee processes.txt | more

If a file being written to does not already exist, it is created.
If a file being written to already exists, the data it previously 
contained is overwritten unless the `-a' option is used.

ycshao

Posted 2011-08-22T19:38:51.063

Reputation: 111