Linux 无法创建备份文件(添加!覆盖)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8428210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot create backup file(add ! to overwrite)
提问by Aditya
Need help. I have been editing a text file in vi , and i was able to save the changes before but now i am getting the above error whenever i am typing command to save the file. Please help .
需要帮忙。我一直在 vi 中编辑一个文本文件,之前我能够保存更改,但现在每当我输入命令来保存文件时,我都会收到上述错误。请帮忙 。
回答by Johnsyweb
You can, as vi
(or, more likely, vim
) is saying force a write by doing:
你可以,因为vi
(或者,更有可能,vim
)是说通过执行强制写入:
:w!
Alternatively, write the file to an alternative location:
或者,将文件写入其他位置:
:w! /path/to/other/location
To check where your backup files are being written (normally):
要检查备份文件的写入位置(通常):
:se backup? backupdir? backupext?
Try to touch
a file in that directory and see if your Operating System gives you an error to enlighten you as to why your editor cannot write there.
尝试touch
该目录中的一个文件,看看您的操作系统是否给您一个错误,以启发您为什么您的编辑器不能在那里写入。
回答by Fredrik Pihl
from within vi, try:
在 vi 中,尝试:
:w!
:help w!
gives the following information:
:help w!
提供以下信息:
*:w!* :[range]w[rite]! [++opt] {file} Write the specified lines to {file}. Overwrite an existing file.
*:w!* :[range]w[rite]! [++opt] {file} Write the specified lines to {file}. Overwrite an existing file.
回答by Piotr P?czek
Had the same problem. It was because I installed vimconf as root. You need to change rights of files in ~/.vim directory and change owner to your user.
有同样的问题。那是因为我以 root 身份安装了 vimconf。您需要更改 ~/.vim 目录中文件的权限并将所有者更改为您的用户。
sudo chmod 0750 ~/.vim
sudo chown user ~/.vim
回答by naamadheya
Had the same problem. Tried all options as above but it did not work. Then when I checked my disk space, it was full. Once I cleared some space then I was able to write back to file again.
P.S: This was in linux.
有同样的问题。尝试了上述所有选项,但没有奏效。然后当我检查我的磁盘空间时,它已满。一旦我清除了一些空间,我就可以再次写回文件。
PS:这是在linux中。
回答by Greg Bell
Another possibility is that you put your backups in a centralized location (e.g. /tmp) and you edited a particular file as root. Then, the backup file will be owned by root and un-writeable by you as a mere mortal later.
另一种可能性是您将备份放在一个集中的位置(例如 /tmp)并以 root 用户身份编辑了一个特定的文件。然后,备份文件将归根用户所有,以后您将无法作为普通人写入。
In this case, the suggestion above to touch /tmp/atestfile won't show the problem! You'll have write permissions, no problem, but not to the particular backup file vim is trying to write.
在这种情况下,上面的触摸 /tmp/testfile 的建议不会显示问题!您将拥有写入权限,没问题,但不能写入 vim 尝试写入的特定备份文件。
Remove the file as root (sudo rm).
以 root 身份删除文件 (sudo rm)。
Note that the reason w! works is because vim writes the file without writing a backup file (you're insisting that it write despite the error).
注意原因w!有效是因为 vim 在不写入备份文件的情况下写入文件(尽管出现错误,您仍坚持要写入)。
回答by Aaron Oommen
I had this same problem. Turns out it was due to running out of disk space. try creating a file using Ex) touch test.txt
. If you get a message saying touch: cannot touch test.txt: No space left on device
you will need to clear up space on your disk
我有同样的问题。原来是因为磁盘空间不足。尝试使用 Ex) 创建文件touch test.txt
。如果您收到一条消息,提示touch: cannot touch test.txt: No space left on device
您需要清理磁盘空间
回答by TankorSmash
I don't know what the cause was, but I moved by backupdir
from .
to ~/.vim/backups
in my .vimrc and it solved it for me:
我不知道原因是什么,但我在我的 .vimrc 中backupdir
从.
到到~/.vim/backups
,它为我解决了这个问题:
set backupdir=~/.vim/backups
I'd imagine some sort of tool was using the folder the file I was editing it in (Visual Studio 2013, in my case), but I'm not sure.
我想某种工具正在使用我正在编辑它的文件的文件夹(在我的情况下是 Visual Studio 2013),但我不确定。
回答by Manuel Schmitzberger
I've fixed this with:
我已经解决了这个问题:
sudo chown {user} ~/.cache/vim/* -R
where the "{user}" field is your user-name.
其中“{user}”字段是您的用户名。
回答by kintsukuroi
In my case my disk was full.
就我而言,我的磁盘已满。
Here are some commands to verify this and find where the disk space is being taken. In my case it was the PHP log at over 20GB.
这里有一些命令来验证这一点并找到磁盘空间被占用的位置。就我而言,它是超过 20GB 的 PHP 日志。
# see general disk space usage
df -h
# see current file and directory disk space usage. You can go to / and work your way in
du -sh *