Thursday, January 30, 2014

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
download
alternative link download

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.