Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restore files edited by vi

Status
Not open for further replies.

sedawk

Programmer
Feb 5, 2002
247
US
Hi,

I accidently type in :wq in vi when editing a file. The save-and-quit command delete the useful information on the file. I know the original file copy was stored in some temporary directory, say 1 hour ago, 2 hours ago ect so that it can be restored. I just need the file copy that was saved yesterday.

Can someone tell me where that directory is?

Thanks a lot

 
vi stores a working copy using a naming standard something like

real filename= "foobar.txt"
vi tempfilename = ".foobar.W4Sgsf4"

The tempfile is stored alongside the orignal file.

My understanding is that this tempfile is deleted when you exit vi normally. It remains if you lose your connection during a vi session or otherwise abnormally abandon a vi session.

I suspect you're out of luck.

D.E.R. Management - IT Project Management Consulting
 
Depending on what flavor of vi you're using and how it's configured, it might have dropped a backup file somewhere.

Often, the backup file is stored in the same directory as the original file, and it's named the same thing as the original with a tilde (~) appended to the end (ls can be set up to ignore files with such names).

Otherwise, you'll have to check to see how your particular editor is set up to handle backups. For example, if your vi is really vim, the value of the backupcopy option should tell you how it makes backups; by default, vim uses the tilde naming scheme. Check the documentation for your editor if it's not vim.

This is important: until you find if, where, and how the backup is stored, do not use any editor to edit the file. You may overwrite the only good backup.
 
Yup. After using vi(m) over the weekend, it definitely stored the temporary file in the same folder as the original. Sometimes it deleted the temporary file on exit, sometimes it did not.

Carlsberg don't run I.T departments, but if they did they'd probably be more fun.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top