sudo回声“某物" >> /etc/privilegedFile不起作用 [英] sudo echo "something" >> /etc/privilegedFile doesn't work

查看:103
本文介绍了sudo回声“某物" >> /etc/privilegedFile不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常简单的问题,至少看起来应该如此,关于Linux中的sudo权限.

很多时候,我只想将某些内容附加到/etc/hosts或类似文件中,但最终却无法执行,因为即使使用root,也不允许同时使用>>>. >

是否有某种方法可以使此工作而不必susudo su进入根目录?

解决方案

使用tee --appendtee -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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆