

$ echo ' something' | sudo tee -append file.txtĪs an alternative to the tee command you can simply make sure the redirection happens in a shell with the right permissions: $ sudo bash -c "echo ' something' > file.txt" For the instructions regarding the tee command syntax and the available arguments, use the command’s help argument: tee -help.

See the current version of the tee command by typing: tee -version. Instead of redirecting ‘ something‘ to a truncated file like this: $ sudo echo 'something' > file.txtĭo it like this: $ echo ' something' | sudo tee file.txtĪnd instead of redirecting ‘ something‘ and appending it to a file like this: $ sudo echo 'something' > file.txtĭo the following: $ echo ' something' | sudo tee -a file.txt Use tee to create a log file and see the output in the terminal./testbash.sh tee testbash.log See Help and Version Information. Warning: The tee command without the -a, -append flag will overwrite the file!
#Sudo cat tee how to#
There are several ways of how to solve the “permission denied” error when using sudo with redirection and the first of them is by using the tee command. > or >, is executed not by the sudo echo, but by the current user’s shell (that is not running as root). The construction sudo echo 'something' > file doesn’t work, because the redirection i.e. If you try to echo something to a file that you don’t have permission to write to, you will receive the “permission denied” error.īut, what might seem surprising, if you try to repeat the same echo command with sudo, you will still receive the same “permission denied” error.
