sudo echo
Many people complain that they cant use sudo with echo.
For example people try to do
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.
For example people try to do
sudo echo 1 > /etc/fileTo 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
Comments
Post a Comment
Comments are moderated. No spam please.