无法创建备份文件(添加!覆盖)

发布于 2024-12-20 07:20:23 字数 1556 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

一身仙ぐ女味 2024-12-27 07:20:23

您可以按照 vi(或更可能是 vim)所说的方式强制写入:

:w!

或者,将文件写入另一个位置:

:w! /path/to/other/location

要检查备份的位置正在写入文件(正常情况下):

:se backup? backupdir? backupext? 

尝试触摸该目录中的文件,看看您的操作系统是否给出错误,以提示您为什么编辑器无法在那里写入。

You can, as vi (or, more likely, vim) is saying force a write by doing:

: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.

七堇年 2024-12-27 07:20:23

有同样的问题。尝试了上述所有选项,但没有成功。然后当我检查我的磁盘空间时,它已满。一旦我清除了一些空间,我就可以再次写回文件。
PS:这是在linux下。

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.

抽个烟儿 2024-12-27 07:20:23

有同样的问题。这是因为我以root身份安装了vimconf。您需要更改 ~/.vim 目录中文件的权限并将所有者更改为您的用户。

sudo chmod 0750 ~/.vim
sudo chown user ~/.vim

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.

sudo chmod 0750 ~/.vim
sudo chown user ~/.vim
∝单色的世界 2024-12-27 07:20:23

我也有同样的问题。事实证明这是由于磁盘空间不足造成的。尝试使用 Ex) touch test.txt 创建一个文件。如果您收到一条消息:touch:无法触摸test.txt:No space left on device,您将需要清理磁盘上的空间

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

人│生佛魔见 2024-12-27 07:20:23

我不知道原因是什么,但我在 .vimrc 中通过 backupdir. 移动到 ~/.vim/backups ,它为我解决了这个问题:

set backupdir=~/.vim/backups

我想象某种工具正在使用我正在编辑的文件的文件夹(在我的例子中是 Visual Studio 2013),但我不确定。

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:

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.

梦屿孤独相伴 2024-12-27 07:20:23

我已经解决了这个问题:

sudo chown {user} ~/.cache/vim/* -R 

其中“{user}”字段是您的用户名。

I've fixed this with:

sudo chown {user} ~/.cache/vim/* -R 

where the "{user}" field is your user-name.

饭团 2024-12-27 07:20:23

备份位置可以在.vimrc中给出,例如:

set backupdir=~/.vim/backup

您可能需要自己创建这个目录。

Backup location can be given in .vimrc, e.g.:

set backupdir=~/.vim/backup

You may need to create this directory yourself.

酒绊 2024-12-27 07:20:23

在 vi 中,尝试:

:w!

:help w! 给出以下信息:

<前><代码> *:w!*
:[范围]w[仪式]! [++选择] {文件}
将指定行写入 {file}。覆盖一个
现有文件。

from within vi, try:

:w!

:help w! gives the following information:

                                                       *:w!*
:[range]w[rite]! [++opt] {file}
                        Write the specified lines to {file}.  Overwrite an
                        existing file.
萌吟 2024-12-27 07:20:23

就我而言,我的磁盘已满。

以下是一些命令来验证这一点并查找磁盘空间被占用的位置。就我而言,它是超过 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 *

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.

# 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 *
不一样的天空 2024-12-27 07:20:23

另一种可能性是您将备份放在一个集中位置(例如 /tmp),并以 root 身份编辑特定文件。然后,备份文件将归 root 所有,并且以后您作为凡人将无法写入。

在这种情况下,上面触摸 /tmp/atestfile 的建议不会显示问题!你将拥有写入权限,没问题,但没有 vim 尝试写入的特定备份文件的权限。

以 root 身份删除该文件 (sudo rm)。

注意原因w!有效是因为 vim 写入文件而不写入备份文件(尽管出现错误,您仍然坚持写入)。

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.

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.

Remove the file as 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).

吻风 2024-12-27 07:20:23

我刚刚开始使用 nvim,我发现我的问题是我借来的预制 vimrc 文件中有一个预设源。

grep -rnw ~/.config/nvim/ -e backup
.config/nvim/lua/custom/vimrc:132:set backupdir=~/.backup/,/tmp/

和这里的其他人一样,创建该备份目录清除了我的错误消息(~/.backup/)

I just started using nvim and I found my issue was that my borrowed premade vimrc file had a preset source in it.

grep -rnw ~/.config/nvim/ -e backup
.config/nvim/lua/custom/vimrc:132:set backupdir=~/.backup/,/tmp/

Like others here, creating that backup directory cleared my error message (~/.backup/)

昨迟人 2024-12-27 07:20:23

我认为还值得一提的是,问题可能不是您在备份目录中拥有的权限。对我来说,我正在编写的文件位于根拥有的目录中,尽管该文件是用户拥有的。

I think it's also worth mentioning that the problem might not be the permissions you have in the backup directory. For me the file I was writing was in a root owned directory, although the file was user owned.

人心善变 2024-12-27 07:20:23

如果您正在编辑不属于您的文件,即您正在编辑 root 拥有的目录中的文件,则可能会出现此消息。

你可以在目录中使用这个命令来查看哪些内容是你所拥有的,哪些内容是root所拥有的。

~/test λ  ls -la .
total 8
drwxr-xr-x  2 root      root      4096 Jul 20 01:50 .
drwx------ 27 root      root      4096 Jul 20 01:49 ..
-rw-r--r--  1 user      user         0 Jul 20 01:50 hello

在这种情况下,hello 文件归用户所有,但目录 . 归 root 所有。如果您尝试使用 vim 或 neovim 编辑文件并保存,则会显示错误无法写入备份文件(添加!以覆盖)

因此,要解决这个问题,您可以

sudo chown root:root hello
sudo vim hello

并且它应该按预期工作。

This massage might appear if you are editing a file that is not owned by you, i.e. you are editing a file in a directory owned by root.

you can use this command in the directory to see what is owned by you and what is owned by root.

~/test λ  ls -la .
total 8
drwxr-xr-x  2 root      root      4096 Jul 20 01:50 .
drwx------ 27 root      root      4096 Jul 20 01:49 ..
-rw-r--r--  1 user      user         0 Jul 20 01:50 hello

in this case hello file is owned by user but the directory . is owned by root. if you tried to edit the file and save with vim or neovim, it will display error Can't write to backup file (add ! to override).

so to solve this you can

sudo chown root:root hello
sudo vim hello

and it should work as expected.

葮薆情 2024-12-27 07:20:23

简单,首先释放一些空间,然后重试..如果仍然存在相同的问题,则尝试使用 :w 保存!

Simple first free some space and try again..if still same issue then try to save with :w!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文