home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 30.23 Safer vi Filter-Throughs Chapter 30
vi Tips and Tricks
Next: 30.25 vi -r May not Write Recovered Buffer When You Exit

30.24 vi/ex File Recovery vs. Networked Filesystems

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

Date: Tue, 19 Nov 91 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.

Warning! 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; they'll often show which machine the message originally came from. 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:

% vi -r

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" 
No files saved.

Don't wait too long. Most UNIX systems remove these saved editor buffers every month, week, or even more often.

- JP

Previous: 30.23 Safer vi Filter-Throughs UNIX Power Tools Next: 30.25 vi -r May not Write Recovered Buffer When You Exit
30.23 Safer vi Filter-Throughs Book Index 30.25 vi -r May not Write Recovered Buffer When You Exit

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System