6

In terminal, sometimes I would like to display the standard output and also save it as a backup. but if I use redirection ( > &> etc), it does not display the output in the terminal anymore.

I think I can do for example ls > localbackup.txt | cat localbackup.txt. But it just doesn't feel right. Is there any shortcut to achieve this?

Thank you!

2 Answers 2

9

tee is the command you are looking for:

ls | tee localbackup.txt
Sign up to request clarification or add additional context in comments.

1 Comment

@YolandYan accepting a correct answer is also a way to thank someone for their help.
2

In addition to using tee to duplicate the output (and it's worth mentioning that tee is able to append to the file instead of overwriting it, by using tee -a, so that you can run several commands in sequence and retain all of the output), you can also use tail -f to "follow" the output file from a parallel process (e.g. a separate terminal):

command1 >localbackup.txt    # create output file
command2 >>localbackup.txt   # append to output

and from a separate terminal, at the same time:

tail -f localbackup.txt    # this will keep outputting as text is appended to the file

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.