sudo回声“某物" >> /etc/privilegedFile不起作用 [英] sudo echo "something" >> /etc/privilegedFile doesn't work
问题描述
这是一个非常简单的问题,至少看起来应该如此,关于Linux中的sudo权限.
很多时候,我只想将某些内容附加到/etc/hosts
或类似文件中,但最终却无法执行,因为即使使用root,也不允许同时使用>
和>>
. >
是否有某种方法可以使此工作而不必su
或sudo su
进入根目录?
使用tee --append
或tee -a
.
echo 'deb blah ... blah' | sudo tee -a /etc/apt/sources.list
确保避免在引号内使用引号.
为避免将数据打印回控制台,请将输出重定向到/dev/null.
echo 'deb blah ... blah' | sudo tee -a /etc/apt/sources.list > /dev/null
请记住(-a
/--append
)标志!
只是tee
的作用与>
相同,并且会覆盖您的文件. tee -a
的作用与>>
相似,并将写在文件末尾.
This is a pretty simple question, at least it seems like it should be, about sudo permissions in Linux.
There are a lot of times when I just want to append something to /etc/hosts
or a similar file but end up not being able to because both >
and >>
are not allowed, even with root.
Is there someway to make this work without having to su
or sudo su
into root?
Use tee --append
or tee -a
.
echo 'deb blah ... blah' | sudo tee -a /etc/apt/sources.list
Make sure to avoid quotes inside quotes.
To avoid printing data back to the console, redirect the output to /dev/null.
echo 'deb blah ... blah' | sudo tee -a /etc/apt/sources.list > /dev/null
Remember about the (-a
/--append
) flag!
Just tee
works like >
and will overwrite your file. tee -a
works like >>
and will write at the end of the file.
这篇关于sudo回声“某物" >> /etc/privilegedFile不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!