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

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

问题描述

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

This is a pretty simple question, at least it seems like it should be, about sudo permissions in Linux.

很多时候我只想将某些内容附加到 /etc/hosts 或类似文件,但最终无法添加,因为 >>>> 是不允许的,即使是 root.

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.

有没有什么方法可以使这项工作无需 susudo su 进入根目录?

Is there someway to make this work without having to su or sudo su into root?

推荐答案

使用 tee --appendtee -a.

echo 'deb blah ... blah' | sudo tee -a /etc/apt/sources.list

确保避免引号内的引号.

Make sure to avoid quotes inside quotes.

为避免将数据打印回控制台,请将输出重定向到/dev/null.

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

记住 (-a/--append) 标志!只是 tee>> 一样工作并且会覆盖你的文件.tee -a>> 的工作方式类似,会写在文件的末尾.

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.

这篇关于须藤回声“某事">>/etc/privilegedFile 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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