VI error "Found a swap file by the name"

While opening files with vi editor we come across the following error at times.

E325: ATTENTION Found a swap file by the name “.temp_1.swp” owned by: root dated: Fri Mar 15 16:38:33 2013 file name: /home/user/Desktop/per/globs/tux.think/scripts/temp_1 modified: no user name: root host name: nitin process ID: 3889 (still running) While opening file “temp_1” dated: Fri Dec 21 09:17:16 2012 (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 temp_1” to recover the changes (see “:help recovery”). If you did this already, delete the swap file “.temp_1.swp” to avoid this message. Swap file “.temp_1.swp” already exists! [O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:

The error comes when the the file was not closed cleanly the last time it was opened, and the might done to the while during the last open might not have been saved.

For example when we close the terminal with out Quitting the file, use Cntl+z to close the file or the system shuts down abruptly when the file is open in the editor, in all the these cases vi automatically creates a .swp file of the current open file with the latest contents in it.
The next time we try to open the same file, vi editor realizes that there as swap file present for it and that might be latest file which is required and thus throws this prompt to let the user decide the further course of action.

There are 4 options to choose from

O: Open in read only mode. We can use this to confirm if the file is the latest one or not.
E: If we are not bothered about the lost changes we can directly open it and start editing it.
R: If we want to recover some of the changes that we have failed to save we can choose this option, which will try to recover the last auto saved file.
Q: Quitting with you opening the file
A: Abort the opening of the file and come back to terminal .

After choosing one of the above options and making sure that we have successfully recovered the file, we can prevent vi from throwing the message next time the file is opened we need to remove the swp file using the “rm” command. The swap file name will be “.filename.swp”

Tags: ,
Copyright 2017. All rights reserved.

Posted March 16, 2013 by Tux Think in category "Linux