File backups with sequential numbering

I’ve discovered over the years that sometimes I shouldn’t just dive in and edit a file. That, sometimes, I have grand ideas that aren’t so super. I’ve made edits to files, quit and saved them, then ran them as a script, or read them as a document and said, “Oh boy”. So basically, now, I approach editing files cautiously and if I have any doubt they can be flubbed, then first I will do a backup.

When it is the point where I know a file has to be backed up, first thing I do is check and see if there is a _vault directory. In any location where I had to backup a file previously, I created a _vault directory. After the first time I did this I realized that I was going to have to number these file backups. I reasoned that filename_[0-9][0-9] would be an reasonable format. If an extension was there the entire format would be filename_[0-9][0-9].ext.

As this is something I regularly do, I decided to build a script to make this a bit easier. The usage is basic — I define the file and optionally the destination-directory. If the destination directory remains unspecified then the current directory is used. An example:

$ bckfile file.txt _vault
‘file.txt’ -> ‘_vault/file_01.txt’

The limitation of the script is that files can only contain a period if used for the extension. This is a all but necessary as there would be no easy way to determine in a script if a period in a filename is for an extension or actually a part of the filename.

bckfile can be installed for Arch Linux users as part of the AUR package of my general utility scripts: genscripts-git.

About Todd Partridge (Gently)

Good times, good people, good fun.

Posted on 2013-12-24, in Command Line, Linux, Script. Bookmark the permalink. Leave a comment.

Comments are closed.


Get every new post delivered to your Inbox.

Join 58 other followers

%d bloggers like this: