sudo echo

Many people complain that they cant use sudo with echo.
For example people try to do
sudo echo 1 > /etc/file
To know why this fails, lets break the command in two parts.

sudo echo 1
You are just echoing "1".

> /etc/file
You are trying to write something to file inside /etc for which you need root access. But there is no root access as sudo was needlessly used with echo command.

So to use sudo and echo we need help from one command called tee. With tee you can accomplish the above work.
echo 1 | sudo tee /etc/file
echo 1 | sudo tee -a /etc/file


Popular posts from this blog

[Solved] invalid partition table on /dev/sda -- wrong signature 0.

Squid Access.log Meaning Explained

Send SMS Using Gammu Command Line Tool