How to append tee to a file in Bash?

These are commands I type in the terminal

echo -e "First Line" | tee ~/output.log
echo -e "Second Line" | tee ~/output.log

When I look in the file output.log I only see 'Second Line'. How can I make sure that tee appends (rather than wipes out the file)?

I'd like to be able to see this in the file:

First Line
Second Line

Should I be approaching this another way?

0

1 Answer

echo -e "First Line" | tee ~/output.log
echo -e "Second Line" | tee -a ~/output.log ^^

From man tee:

 Copy standard input to each FILE, and also to standard output. -a, --append append to the given FILEs, do not overwrite

Note: Using -a still creates the file mentioned.

6

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like