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
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
I got this error when I used
git rm
on a file in a directory.I was in something like ~/gitRepo/code/newFeature
In newFeature there was only one file. I did a
git rm
on that file then tried to create a new file myNewFile using vi.Ubuntu showed me as still being inside the newFeature directory but actually
git rm
had removed the whole directory.I had to exit out of vi, navigate up one directory and then recreate the newFeature directory.
That happens to me all the time, I open a root file for writing:
Instead of losing all your changes and re-opening with sudo. See this demo of how to save those changes:
One time Setup demo to create a root owned read only file for a lower user:
First open the file as normal user:
Then make some changes to the file, it warns you its read only. Use this command.
Then write the file:
The permissions are expanded, and the file is saved. You need the exclamation point because you are editing a root file as a lesser user.
Explanation of what that command does:
The :w means write the file. The bang means start interpreting as shell. chmod means change permissions, 777 means full permissions everywhere. The percent means the current file name.
It applies the change. And it ask if you want to re-load. Press "O" for "Ok". Don't reload or you'll lose your changes.
For me there was was quite a simple solution. I was trying to edit/create a file in a folder that didn't exist. As I was already in the folder I was trying to edit/create a file in.
i.e.
pwd folder/file
and was typing
and rather obviously it was looking for the folder in the folder and failing to save.
You just need to access to Gemfile with root access. Before
vi
:command:
then: