SCdF SCdF - 27 days ago 17
Linux Question

How to redirect output to a file and stdout

In bash, calling

foo
would display any output from that command on the stdout.

Calling
foo > output
would redirect any output from that command to the file specified (in this case 'output').

Is there a way to redirect output to a file and have it display on stdout?

Answer

The command you want is named tee:

foo | tee output.file

For example:

ls -a | tee output.file