Ultimate Web Tips

your Wordpress, jQuery, PHP, MySQL, Linux and CSS guide to a successful website

How to sudo echo to a file with help of tee

January 25th, 2012 Linux, by Joakim Ling.

I wasted a good few hours trying to find a good solution on how to save an echoed string with sudo. I tried “sudo echo ..” and lots of different combinations before I made it work.

I used the command “tee” which basically copies the output and copies into a variable or file. Perfect!

echo "String to save " | sudo tee filename.txt > /dev/null

Linux training

If you need to improve your skills try my linux training guide, read more

Back Top