Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

As part of the program I wrote, I constantly read and write data from files. I noticed that as part of doing so, I am inadvertently creating swap .swp files.

What do you think is going on? What would cause swap files to appear if you had to reproduce the problem?

share|improve this question

4 Answers 4

up vote 14 down vote accepted

The .swp file is not a swap file in the OS sense. It is a state file. It keeps your changes since the last save (except the last 200 characters), buffers that you have saved, unsaved macros and the undo structure.

You can read more in VIM's help: vim +help\ swap-file. If there is a crash (power failure, OS crash, etc.), then you can recover your changes using this swap-file. After saving the changes from the swap file to the original file, you will need to exit vim and remove the swap file yourself.

share|improve this answer

.swp files are created by Vim, they should be automatically deleted when you close the file and exit the editor.

share|improve this answer
    
Can they be created from outside of Vim? In my case files are written from my program directly, without using the editor –  Jam Dec 29 '11 at 19:31
    
@JAM: What language and libraries is this program written with? –  jwodder Dec 29 '11 at 20:07
4  
@JAM Generally no, it is a Vim feature. I doubt these files are being written directly from your program without you knowing, it doesn't make sense. It is much more probable that you are confused, these files are being created while you edit the files with Vim, and you are attributing them to your program. –  Juliano Dec 29 '11 at 21:34

.swp files are nothing but a kind of lock file which you editor, generally vim, creates to indicate that file is being edited. This way if you open the file in another vim instance of if someone in the network did that, they'll see a warning that the file is being edited.
You need not to delete them manually. You editor will remove the swap file once you close the file in your editor.

share|improve this answer

I just executed a mv command on a 31GB file and a 13GB .swp file was created, no editing involved.

mv X.csv Y.csv created Y.csv and .Y.csv.swp

CentOS 6.5, ext4 file system

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.