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.

Using vim I keep getting a message saying "Swap file xxx already exists" when I'm editing an apache config. However, I don't see it in the working directory on in tmp. How do I delete this?

share|improve this question

migrated from serverfault.com Feb 29 '12 at 3:57

This question came from our site for professional system and network administrators.

4 Answers 4

up vote 7 down vote accepted

Vim swap files are normally hidden (Unix hidden files begin with a .). In order to view hidden files as well as regular ones, you need to ls -A (mnemonic: A for All). That should show you whether a swap file is there or not.

share|improve this answer
    
Perfect, there it is... thank you! –  dave Feb 29 '12 at 14:58

In the message, you should see the full path to the file. You can rm it by copy-pasting the path as follows:

rm -f /path/to/the/file
share|improve this answer

This happens only when the file you were trying to edit is not saved completely on to the disk. Scenarios are :

  1. You shut down your system improperly, when a file is still open in vi/vim.

  2. when your file is being accessed concurrently via different/same consoles in vi.

vi/vim creates a .swp file whenever a file is opened in vi/vim. Everytime a file is opened in vi/vim, vi/vim checks for this file and if found this warning pops up

This is can be avoided in two ways

  1. one by deleting the .swp file which is named as

"path/of/the/file/you/were/editing/.your_file_name.swp"

  1. you can also opt for recover mode of vi/vim when opening the file and pressing recovery option .

I am just talking about the first scenario and it is safe for only that scenario. Scenario second is the different case.

share|improve this answer
    
If there were unsaved changes, you can recover them using vi -r (or vim -r if you prefer). I usually write the recovered file to a temporary file and diff it against the main file. (I don't quite trust the recovery not to lose information.) –  Keith Thompson Feb 29 '12 at 3:26

If the file you're editing is called httpd.conf then the swap file will be called .httpd.conf.swp. It is hidden unless you add -a to your ls arguments.

ls -a /etc/httpd/conf/
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.