## 17.19. vi File Recovery Versus Networked Filesystems

Have you ever used the vi -r command to recover a file? It lets you get a file back that you were editing when the system crashed or something else killed your editor before you could save. The system may send you an email message something like this:

>     Date: Thu, 19 Nov 1999 09:59:00 EST
>     To: jerry

>     A copy of an editor buffer of your file "afile"
>     was saved when the system went down.
>     This buffer can be retrieved using the "recover" command of the editor.
>     An easy way to do this is to give the command "vi -r afile".
>     This works for "edit" and "ex" also.

Section 17.20

Your files are saved under a directory named something like /usr/preserve. Follow the instructions and you'll get back your file, more or less the way it was when you lost it.

If your computers have networked filesystems, such as NFS, there's a wrinkle in the way that vi -r works. It may only work right on the specific computer where you were editing a file. For example, if you're editing the file foo on the host named artemis and it crashes, you may not be able to log on to another host and do vi -r foo to recover that file. That's because, on many hosts, temporary files (like editor buffers) are stored on a local filesystem instead of on the networked (shared) filesystems. On this kind of system, you may need to log on to artemis to recover your lost editor buffer.

If you don't remember which computer you were using when the file was lost, check the "Received:" lines in the email message header;[49] they'll often show from which machine the message originally came. Also, if you don't remember what files are saved on a machine, you can usually get a list of your saved files by typing vi -r without a filename:

> [49]Many email programs hide these header lines from you. You might need to set a "show all header fields" option first.

>     % vi -r
>     /var/preserve/jerry:
>     On Wed Jul 17 at 08:02 saved 15 lines of file "/u/jerry/Mail/drafts/1"
>     On Sun Aug 25 at 18:42 saved 157 lines of file "doit"
>     /tmp:
>     No files saved.

Don't wait too long. Many Unix systems remove these saved editor buffers every month, week, or sooner.

-- JP

Copyright © 2003 O'Reilly & Associates. All rights reserved.