/etc/apt/sources.list" E212: Can't open file f

2019-03-07 20:12发布

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

10条回答
倾城 Initia
2楼-- · 2019-03-07 20:50

Try to connect as root and then edit file. This works for me

查看更多
\"骚年 ilove
3楼-- · 2019-03-07 20:54

Or perhaps you are on a readonly mounted fs

查看更多
你好瞎i
4楼-- · 2019-03-07 21:00

I referenced to Zsolt in level 2, I input:

:w !sudo tee % > /dev/null

and then in my situation, I still can't modify the file, so it prompted that add "!". so I input

:q! 

then it works

查看更多
Viruses.
5楼-- · 2019-03-07 21:02

for me worked changing the filesystem from Read-Only before running vim:

bash-3.2# mount -o remount rw /
查看更多
孤傲高冷的网名
6楼-- · 2019-03-07 21:05
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 as sudo vim FILE. Or if you don't want to leave your existing vim session (and now have proper sudo rights), you can issue:

:w !sudo tee % > /dev/null

Which will save the file.

HTH

查看更多
淡お忘
7楼-- · 2019-03-07 21:06

It might be possible that the file you are accessing has a swap copy (or swap version) already there in the same directory

Hence first see whether a hidden file exists or not.

For example, see for the following type of files

.system.conf.swp

By using the command

ls -a

And then, delete it using ...

rm .system.conf.swp

Usually, I recommend to start using super user privileges using ...

sudo su
查看更多
登录 后发表回答