隐藏文件swap

在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:**

出现这个提示信息一般有两个原因:

  1. 文件被其他终端打开正在编辑,同时另外一个终端也打开了这个文件
  2. 之前编辑这个文件的终端意外崩溃,文件可能没有被保存

Linux是怎么给出这个提示的?

当我们在使用vim打开一个文件时候,Linux同时会产生一个隐藏文件.filename.swap,这个文件保存到被编辑文件的同级目录下.当有其他终端或者用户打开这个文件进行编辑的时候,系统发现这个存在这个隐藏文件,就会给出上面的提示.

这个.filename.swap有什么作用?

  1. 防止不同终端或用户同时编辑同一个文件,造成文件内容和期望内容不符,这个有点类似于多个进程同时向一个文件写内容的过程,这个过程我们程序也要处理这种数据不一致的情况,只是这里直接给出了提示交给使用者来处理.

  2. 用于恢复终端意外崩溃没有被保存的文件

.filename.swap如何恢复未保存的文件?
vim -r filename

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值