【问题标题】:Why some programs are able to edit /etc/hosts while others are not?为什么有些程序可以编辑 /etc/hosts 而有些则不能?
【发布时间】:2017-01-27 08:27:29
【问题描述】:

我尝试使用 Emacs、VSCode 等(当然是使用 sudo)编辑我的 /etc/hosts 文件,但它一直说我没有编辑该文件的权限。

然后我尝试了 Vim、Nano 和 Atom……它们能够编辑和保存文件。

(运行 echo 'some host' | sudo tee -a /etc/hosts 也可以正常工作)。

那是为什么呢?为什么有些编辑器可以毫无问题地编辑文件,而有些则不能?

【问题讨论】:

  • sudo /usr/bin/emacs /etc/hosts 为我工作。

标签: unix vim emacs editor hosts


【解决方案1】:

尝试使用本地 emacs 打开C-x C-f /sudo::/etc/hosts

【讨论】:

  • 确实有效,谢谢。但是为什么它不能像使用 vim 一样只使用 sudo emacs file 呢?
  • 正如@choroba 所说,sudo emacs /etc/hosts 也适用于我。这似乎不是 Emacs 的问题,可能与您本地的 sudoers 配置有关,
猜你喜欢
  • 2020-07-25
  • 1970-01-01
  • 1970-01-01
  • 2014-03-19
  • 1970-01-01
  • 1970-01-01
  • 2017-08-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多