CLI tricks - sudo permission denied
Posted by gregster on 26 Apr 2012 in R & D
Bash commands using sudo AND redirect can fail on the redirect because sudo permissions are not passed on to the next stage in your command.
For example, the following failed for me with a permission denied error:
sudo echo "something important" >> /etc/apt//mirror.list
It failed because the bit after the final double-quote is a redirect apparently, and not part of the original echo command. The solution is to wrap the whole thing up thusly:
sudo bash -c "echo \"something important\" >> /etc/apt//mirror.list"