When I attempted to edit a file, index.php, using the vi editor, I saw the following message:
E325: ATTENTION Found a swap file by the name ".index.php.swp" owned by: joe dated: Mon Feb 20 19:36:11 2017 file name: ~joe/www/UVNC/index.php modified: YES user name: joe host name: example.com process ID: 19776 While opening file "index.php" dated: Mon Feb 20 19:38:44 2017 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 index.php" to recover the changes (see ":help recovery"). If you did this already, delete the swap file ".index.php.swp" to avoid this message. Swap file ".index.php.swp" already exists! [O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:
I hit the q
key to return to the
Bash
shell prompt. When I compared the time stamps on the current version of the
file and the .swp file, I saw that the current version had a time stamp 2
minutes after the time stamp for the .swp file.
$ ls -al | grep 'index.php' -rw-rw-r--. 1 joe joe 7571 Feb 20 19:38 index.php -rw-r--r--. 1 joe joe 20480 Feb 20 19:36 .index.php.swp $
Note: you need to use the -a
option with the
ls command,
since any files that have a name beginning with a period are hidden by
default and not displayed by the command unless that option is used.
I wanted to know what the difference was between the .swp version and the current version to determine if I might should recover the file from the .swp version. But you can't just use the diff utility to perform a comparison of the two files to determine their differences, since the .swp file is a binary file.
$ diff index.php .index.php.swp Binary files index.php and .index.php.swp differ $
But, I can choose R
for recover when opening the file and
then write the contents of the file out to another file, e.g., I could
use :w temp.php
and then :q!
to quit without saving
the file. I can then compare the two files with the diff command.
$ diff index.php temp.php 208,210c208,209 < via VNC for remote administration and also still use the < <a href="https://en.wikipedia.org/wiki/File_transfer" rel="nofollow">file < transfer</a> capability provided in UltraVNC.</p> --- > via VNC for remote administration and also still use the file transfer > capability provided in UltraVNC.</p> $
I can, in this case, see I made only one small change to the file that is
contained in the index.php
file, but not the .index.php.swp
file, so I don't need the .swp file and can delete it along with
the temporary file I created for performing the comparison.
$ rm .index.php.swp $ rm temp.php $