Deleted directory with files still open in vim (undelete?)

1k views Asked by At

Help! Instead of cp -Rf dir dir.bak to backup my active project, I did rm -Rf dir dir.bak. It doesn't get much worse than that :(

I've run extundelete --restore-directory on my ext3 partition and it restored some of my directory.

My hope is that I still have vim open. Does vim save each file's content in a memory buffer, even when not in that vim tab? I have two vim tabs open, about 6 windows in each tab. In full, I'm about to lose 30 source files :(

Is there a way to do a :wa! in vim when the underlying directory has been removed? If I re-create the underlying directory, vim still can't save the files I guess because inodes to open files are invalid.

Is there a way I can still save all of the buffers I have open in vim to a new directory? I don't know what representation of the file the buffers contain. If I switch vim tabs (I haven't yet), it will try to re-read those files from disk right?

Any creative solutions inside and outside of vim GREATLY appreciated!!

2

There are 2 answers

1
Uku Loskit On

It should work if you recreate the folders. If the files are open in the buffers, they are in memory. Buffers just store the path where to save the filenames. Inodes are filesystem specific implementation details that vim knows nothing about.

If the directory tree is not very difficult to recreate, you can just try :wa until you have recreated all the missing folders.

0
eplictical On

For the problem of accidentally deleting things, I've done alias rm=trash-put, which will put deleted files in the trash bin for possible later retrieval. I got that information from here: http://www.webupd8.org/2010/02/make-rm-move-files-to-trash-instead-of.html