Last updated 5 years ago
Was this helpful?
在shell命令行中,有时候需要给一个root用户的文件添加内容,但是当前shell执行用户是普通用户身份,则会出现如下执行权限不足的报错
root
解决的方法有以下两种:
使用sudo tee -a命令,通过管道传递需要添加的内容给tee,由于tee通过sudo执行,就具有权限写入文件
sudo tee -a
tee
sudo
使用sudo bash -c命令,使得整个shell都具有root用户权限
sudo bash -c
$ echo "export PATH=$PATH:/opt/bin" >> /etc/profile -bash: /etc/profile: Permission denied
echo "export PATH=$PATH:/opt/bin" | sudo tee -a /etc/profile
sudo bash -c "echo 'export PATH=$PATH:/opt/bin' >> /etc/profile"