E325:注意 Vi 中交换文件已存在错误

E325:注意 Vi 中交换文件已存在错误

我之前已经更改过环境变量。当我尝试使用以下命令时:

sudo vi /etc/environment

我收到以下警告/错误,我不知道下一步该做什么。

E325: ATTENTION
Found a swap file by the name "/etc/.environment.swp"
      owned by: root   dated: Wed Apr 18 15:03:44 2018
     file name: /etc/environment
      modified: no
     user name: root   host name: my-desktop
    process ID: 6410
     [not usable on this computer]
While opening file "/etc/environment"
         dated: Wed Apr 18 14:49:02 2018

(1) Another program may be editing the same file.  If this is the 
case,
be careful not to end up with two different instances of the same
file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r /etc/environment"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file "/etc/.environment.swp"
to avoid this message.
"/etc/environment" 6 lines, 389 characters
Press ENTER or type command to continue

那么有人可以向我解释下一步该做什么以及这条消息的真正含义吗?

更新:我尝试按照建议进行操作。我按下e它打开了环境文件然后我按下i编辑它并更改我的 nodejs 版本(最初它是 9.x 我把它改为 8.x)然后我按下Esc然后shift+;然后然后wq|x我终于按下Enter它关闭了 vi 编辑器之后我再次运行了相同的命令但它给了我同样的错误但进一步的更新说明NEWER than swap file!

完整讯息如下:

E325: ATTENTION
Found a swap file by the name "/etc/.environment.swp"
      owned by: root   dated: Wed Apr 18 15:03:44 2018
     file name: /etc/environment
      modified: no
     user name: root   host name: my-desktop
    process ID: 6410
     [not usable on this computer]
 While opening file "/etc/environment"
         dated: Mon May 14 16:53:13 2018
  NEWER than swap file!

(1) Another program may be editing the same file.  If this is the 
case,
be careful not to end up with two different instances of the same
file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r /etc/environment"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file "/etc/.environment.swp"
to avoid this message.
"/etc/environment" 7 lines, 390 characters
Press ENTER or type command to continue

所以不知道该如何解决!

答案1

这意味着您或其他用户已经开始编辑该文件,并且其中有未保存的更改。您可能打开了该文件,开始编辑它,然后退出 Vi 而没有写入任何内容。

说明书会告诉你该怎么做。

您可以按r恢复文件,然后您将看到未保存更改的版本。进行编辑。

如果你不想恢复未保存的更改,请按q退出并删除消息中提到的文件

sudo rm /etc/.environment.swp

然后您可以再次打开它并找到最后保存的版本。

当您想要保存更改并退出时,请按esc并输入:wq

但是,你确定要编辑吗/etc/environment?考虑一下是否最好使用每个用户的配置文件,例如~/.profile

相关内容