vim出現“E212: Can't open file for writing”的處理辦法


在使用vim 對文件或配置進行編輯的時候,在保存時發現當前用戶沒有寫權限。又不想放棄當前編輯的內容,怎么辦呢?

來自stackoverflow
“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. ”

這樣文件的所有者是root,依然沒有寫的權限。只需更改文件的所有者和組:

[sany@sanshui code]$  sudo chown 用戶名:組名  文件名

當你用上述方法強制寫的時候,會提示如下:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

【linux總是這么可愛大笑


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM