我想要做:
echo "something" >> /etc/config_file
但是,由于只有root用户对该文件具有写权限,所以我不能这样做。但是以下内容也不起作用。
sudo echo "something" >> /etc/config_file
在这种情况下,是否有一种方法可以附加到文件,而不必先使用sudo
'd编辑器打开它,然后手动附加新内容?
使用tee -a
(或tee --append
)与sudo
tee - read from standard input and write to standard output and files
[...]
-a, --append
append to the given FILEs, do not overwrite
[...]
所以你的命令变成
echo "something" | sudo tee -a /etc/config_file
tee
与管理权限相比,执行Bash的优势在于
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句