I am trying to edit sources.list using vi editor but getting the following error while saving the file:
/etc/apt/sources.list" E212: Can't open file for writing
本文介绍了解决在使用Vi编辑器修改/etc/apt/sources.list文件时遇到的写保护错误的方法。该错误可能是由于权限不足导致,文中提供了两种解决方案:一是通过sudo命令以超级用户身份打开文件;二是利用特殊命令在当前Vi会话中保存更改。
I am trying to edit sources.list using vi editor but getting the following error while saving the file:
/etc/apt/sources.list" E212: Can't open file for writing
For some reason the file you are writing to cannot be created or overwritten.
The reason could be that you do not have permission to write in the directory
or the file name is not valid.
Vim has a builtin help system, I just quoted what it says to :h E212. You might want to edit the file as a superuser like sudo vim FILE. Or if you don't want to leave your existing vim session (and know have proper sudo rights), you can issue:
:w !sudo tee % > /dev/null
Which will save the file.
HTH

被折叠的 条评论
为什么被折叠?