Creating auto backups with vi

vib is a "wrapper" for vi which, prior to invoking the editor, makes a backup of each file specified on the command line. I find it particularly useful for editing critical configuration files from which inadvertant errors may not show up immediately. But I also use it for the more "hack" work (C coding, etc ...).

The backups are created in a sub-directory called ".old" immediately under the directory containing each file. This gets around the problem of having multiple re-named copies hanging around in the main editing directory (which is a pain if you use a shell such as "bash" and make heavy use of its "file name completion" ability ... it gets confused and can never decide which file you really want!)

A ".YMDH" (year, month, day and hour) suffix is appended to each filename as it's copied into the .old directory. (Restricting the resolution of the suffix to "hour" miminises the number of copies created during a long session.)

Having a large number of backups for particular files in the one place has helped me on numerous occasions. For example, I recently needed a back version of a Perl script ... I went to the appropriate .old sub-directory, copied back the exact version I needed (from 5 months ago), and had the "restored" functionality I wanted on-line again in less than 5 minutes.

These sub-directories full of "back" versions of configs and scripts are also great for just doing quick "diff" operations when everything seems to be going haywire!


If you "vib" the same file twice within the same hour, the script simply tells you that a backup already exists, and it asks if you'd like to overwrite it. The default (by hitting the CR key) is no, ie: just proceed to edit without over-writing that existing backup.

The script also has a special "hack" for editing the infamous /etc/passwd file. (I included that because I found myself editing it so often. Simply typing "vib passwd" from anywhere will call "vipw" (the special password editing function) if it exists, and will start editing /etc/passwd. You may of course prefer to delete that particular bit of the script.)

Typing "vib" (no args) gives brief usage. "vib -+" provides fuller help.


As of June 15, 2001, vib now generates lock files to guard against more than one edit occurring on a given file at the same time. This protects you against 'hidden' sessions in other windows or other users.


  Back to (Bluehaze) software archive page

 Bluehaze home page