在Linux上使用vim打开一个文件的时候,有时候会出现下面这个提示
**E325: ATTENTION
Found a swap file by the name “.upgradeserver.log.swp”
owned by: root dated: Sat Jun 3 13:32:32 2017
file name: /var/log/uclog/upgradeserver.log
modified: no
user name: root host name: dev
process ID: 22083 (still running)
While opening file “upgradeserver.log”
dated: Fri Jun 2 07:19:40 2017
(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 upgradeserver.log”
to recover the changes (see “:help recovery”).
If you did this already, delete the swap file “.upgradeserver.log.swp”
to avoid this message.
Swap file “.upgradeserver.log.swp” already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:**
出现这个提示信息一般有两个原因:
- 文件被其他终端打开正在编辑,同时另外一个终端也打开了这个文件
- 之前编辑这个文件的终端意外崩溃,文件可能没有被保存
Linux是怎么给出这个提示的?
当我们在使用vim打开一个文件时候,Linux同时会产生一个隐藏文件.filename.swap,这个文件保存到被编辑文件的同级目录下.当有其他终端或者用户打开这个文件进行编辑的时候,系统发现这个存在这个隐藏文件,就会给出上面的提示.
这个.filename.swap有什么作用?
防止不同终端或用户同时编辑同一个文件,造成文件内容和期望内容不符,这个有点类似于多个进程同时向一个文件写内容的过程,这个过程我们程序也要处理这种数据不一致的情况,只是这里直接给出了提示交给使用者来处理.
用于恢复终端意外崩溃没有被保存的文件
.filename.swap如何恢复未保存的文件?
vim -r filename