What are Unix swap (.swp) files?
原文: http://www.networkworld.com/article/2931534/it-management/what-are-unix-swap-swp-files.html
---------------------------------------------------------------------------------------------------------------
When someone mentions a "swap file", the first thing that comes into your mind might be the kind of file that you would create to increase the swap space on a Unix system. Think swapfile and the swapon command. But there's another kind of swap file that comes into play, generally when you're trying to edit a file that might have encountered some difficulties during a prior edit. That type of swap file is created by your system to help ensure that you don't lose important file content when something goes wrong. And it generally sits in the same directory as the original file and has .swp as its extension.
These swap files store content for the specific file -- for example, while you're editing a file with vim. They are set up when you start an edit session and then automatically removed when you're done unless some problem occurs and your editing session doesn't complete properly. In that case, vim will offer you a chance to recover your work where you left off.
If you were sitting in a directory containing a file that is currently being edited with vim, you might see the type of file that I'm referring to. If the file being edited were called chkAccts.sh, for example, the swap file set up when you begin your edit would be called .chkAccts.sh.swp and you could spot it sitting in the same directory were you to look for it from another window or login session.
These swap files have two purposes: 1) to help keep you from losing content if you run into some kind of editing glitch and 2) to keep you from editing the same file at the same time from each of two sessions. If an editing session crashes or you try to edit the file a second time from a separate window, vim will warn you by issuing a fairly verbose message indicating that the swap file exists and teling you that the reason is one of the two that I just mentioned. It will also supply the command needed to start the editing session using the contents of the swap file.
If you edit the file again, despite the warning, but fail to remove the swap file, vim will continue to warn you. It will show you something like this. In fact, it will show you this every time you edit the file -- as long as the .swp is still sitting there under your fingertips.
E325: ATTENTION
Found a swap file by the name ".chkAccts.sh.swp"
owned by: root dated: Thu May 28 09:33:16 2015
file name: /home/shs/bin/chkAccts.sh.swp
modified: YES
user name: shs host name: boson
process ID: 11354
While opening file "chkAccts.sh.swp"
dated: Thu May 28 10:41:05 2015
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 ShareAccessReview.csv"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file ".ShareAccessReview.csv.swp"
to avoid this message.
"chkAccts.sh.swp" 45L, 2941C Using swap file ".chkAccts.sh.swp"
Original file "/home/oracle/data/chkAccts.sh"
E308: Warning: Original file may have been changed
Recovery completed. You should check if everything is OK.
(You might want to write out this file under another name
and run diff with the original file to check for changes)
Delete the .swp file afterwards. Press ENTER or type command to continue
You might recognize some of the original file the contents if you try to look at a .swp file, but it's not going to look like exactly like the original file. It will contain your original text, but also some other content. It is, after all, a dump of some portion of your editing. They shadow your editing session.
$ cat .isanumber.swp
3210#"! Utp▒N▒D▒ad=usvad▒▒▒▒▒▒▒xutfi echo "$1 is a number"else exit 1 echo "ERROR: not a number!" > /dev/stderrthenif ! [ "$1" -eq "$1" 2> /dev/null ]#!/bin/bash$
If you want to abandon prior editing changes that might be recorded in the swap file, just look for a file with the same name as the one you were editing, but starting with a period and having the extension .swp added to the end and remove it. Problem resolved.
$ rm .chkAccts.sh.swp
rm: remove regular file `.chkAccts.sh.swp'? y
If, for some reason, you want your swap files to be stored somewhere other than your current directory, you can create a .vimrc file and insert a command such as directory=/tmp to use a different directory. You can also disable the behavior (creating swap files) altogether by setting up your .vimrc file like the one shown below. Though I think the protection is generally a good thing, some Unix folks prefer to use other means to ensure their files aren't subject to loss and think that the appearance of .swp files on their systems is more trouble than it's worth. The tradeoff should probably depend on whether you waste a lot of time cleaning up .swp files that you don't need or are grateful every time one of them saves work in progress when you editing session runs into problems.
$ cat .vimrc
set directory=/tmp
set nobackup
set noswapfile
Swap files don't generally cause a lot of trouble, but can be annoying if you keep having to look at vim's warnings every time you go to edit a file. A little cleanup and they'll stop generating warnings.
What are Unix swap (.swp) files?
What are Unix swap (.swp) files?的更多相关文章
- Supervisor(Linux/Unix进程管理工具)安装与配置
参考链接:https://blog.csdn.net/xyang81/article/details/51555473 Supervisor(http://supervisord.org/)是用Pyt ...
- Git 一些关于 Git、Github 的学习资源
一些关于 Git.Github 的学习资源 昨天浏览 Github 的是时候发现了 Githug 这个游戏,这个游戏用来帮助菜鸟们学习使用 Git 的. Githug is designed to g ...
- 大神的vim配置
大神的vim配置,O(∩_∩)O spf13-vim : Steve Francia's Vim Distribution __ _ _____ _ ___ _ __ / _/ |___ / __ _ ...
- docker Dockerfile 创建镜像
Docker 组件 1. docker client : docker的客户端 2. docker server : docker daemon的主要组成部分,接受用户通过docker client发 ...
- slatstack Master的配置
Salt系统非常简单并且易于配置,Salt系统的两个组件都有各自的配置文件.如"salt-master"是通过主配置文件来配置的,"salt-minion"是通 ...
- Solaris/Linux 命令手册
无意翻到之前收藏的一个文档,共享一下. Solaris/Linux 命令手册 1. 系统 # passwd:修改口令 # exit:退出系统 2. 文件 # cp:复制文件或目录,参数:-a递归目录, ...
- man lsof
LSOF(8) LSOF(8) NAME lsof - lis ...
- shell命令lsof
PREFACE linux一切皆是文件,共有7中文件类型 1.普通文件(regular file) 2.目录文件(directory file) 3.块特殊文件(block special file) ...
- 后台进程管理supervisor
一.安装 该工具是python的一个软件包,需要安装python及其python-setuptools 二.安装完后会在python的bin目录下找到对应的命令文件 三.安装supervisor为服务 ...
随机推荐
- 专题六:UDP编程
引用: 前一个专题简单介绍了TCP编程的一些知识,UDP与TCP地位相当的另一个传输层协议,它也是当下流行的很多主流网络应用(例如QQ.MSN和Skype等一些即时通信软件传输层都是应用UDP协议的) ...
- Android Retrofit+Rxjava2问题小记
网络请求有个问题就是取消操作. 在Rxjava1中,调用subscribe之后会返回Subscription,然后利用CompositeSubscription进行统一管理. 在Rxjava2中,调用 ...
- java实现麦克风自动录音
最近在研究语音识别,使用百度的sdk.发现只有识别的部分,而我需要保存音频文件,并且实现当有声音传入时自动生成音频文件. 先上代码: public class EngineeCore { String ...
- Activity随笔
Activity的生命周期 1.正常情况下的生命周期 onCreate: Activity正在被创建,生命周期中的第一个方法,常在此方法中做一些初始化工作,比如调用setContentView方法, ...
- 使用WAS寄宿net.tcp WCF服務
首先添加Windows Features 確保打開以下服務 Net.Tcp Listener Adapter Net.Tcp Port Sharing Service Windows Process ...
- c++写入txt
用ofstream 输出流,#include <fstream> ofstream outf; outf.open("abc.txt");outf<<123 ...
- python json格式和csv文件转换
python json格式和csv文件转换 上代码 import csv import json ''' json格式示例 [{ "firstName":"Bill&qu ...
- 「 Luogu P2230 」X 「 Vijos 1142 」 HXOS系统
题目描述可能稍有偏差,但实质上是一样的. 看下面 题目大意 题面这么长,先说说题意吧. 就是有一个操作系统,他的存储方式是树形的.其中分为文件和目录(文件夹)每一个子目录下只能存储 $K$ 个文件或目 ...
- Linux 安装 Tomcat 详解
说明:安装的 tomcat 为解压版(即免安装版):apache-tomcat-8.5.15.tar.gz (1)使用 root 用户登录虚拟机,在根目录下的 opt 文件夹新建一个 software ...
- pipreqs(找当前项目依赖的包)
pipreqs pipreqs可以帮你找到当前项目的所有组件及其版本.就是当别人给你一个程序的时候,你要在自己电脑上运行起来,就需要安装程序所依赖的组件,总不能自己一个一个找吧. # 安装 pip3 ...