Your Linux Data Center Experts

After an unclean system shutdown I always have these vim tmp files laying around that cause annoying messages to come up when I edit files that I had previously edited while my system went down. These things are spread out all over the file-system. I had a cron job set up that would use locate to hunt them down, but this caused two problems: it required more than a day for the files to be removed, because updatedb had to be updated, then I usually gave it 7 days of grace time in case I was editing something for multiple days…

The worst problem was a subtle bug in this code which caused me to have to recover my home directory from backups. This is why RAID is not a backup plan. :-)

I've recently switched to a new mechanism though, which works much, much better. Read on for more…

Ideally I want these temporary files removed on the next boot, or shortly after… However, I'm always reluctant to just simply remove them, because they can be used to recover mangled files – allegedly. I can't remember the last time that I needed that and it did anything useful for me.

The first thing I did was to set up a ~/.vim-tmp directory, and add this line to my ~/.vimrc: set directory=~/.vim-tmp

This causes all temporary files to be written into a central directory. The next piece of magic, which I had never used before, was to use the “@reboot” time-specifier in my crontab:

@reboot ~/bin/archivevimswap >/dev/null 2>&1

Then I put together this simple script that saves the previous copy of my .vim-tmp directory, and makes a new one at boot time:

#  Keep a copy of the old vim swap directory at boot time.

cd ~ || exit 0
rm -rf .vim-tmp.old
mv .vim-tmp .vim-tmp.old
mkdir .vim-tmp
chmod 700 .vim-tmp
comments powered by Disqus

Join our other satisfied clients. Contact us today.