Preventing disaster from the command line - a naming convention for backing up files that makes sense - with a semantic suffix for files

computer screen with code

Working in the command line is fun. It helps you focus. But sometimes, you do things that you may need to recover quickly from.

Eventually, you end up with 15 versions of your file, and not know a) how to recover or b) which to recover with

  • file.txt
  • file.txt_bak
  • file.txt_bak1
  • file.txt_bak2
  • file.txt_bakthursday

This is horrible. Let's avoid it.

But first, the original.

What I've learned is that you should make a copy called file.text_orig instead of file.txt_bak because after 11 thousand changes, you're not sure if it was bak2 or bak1 that you used last. Keeping the original file distinct will help you recover to a pristine state.

  • cp file.txt file.txt_orig

But sometimes, you need all the changes you've made, and don't want to recover to a state without them. Read on experienced friend!

Then, what works

When you make changes like add lines to files, comment, or uncomment lines etc. you'll want to keep them. In this case, once you get everything running, you create and overwrite a file that explicitly says it was last working - regard:

  • cp file.txt file.txt_lastworking

That's your real backup file. Now you're free to make changes to the working file (pun intended) without the suffix as you please.

Now for what you have to do right now

You'll eventually have to make multiple changes to a file sometimes. If you have multiple changes to make and want to test them individually, or if you want to change multiple things at a time you can do that with:

  • cp file.txt file.txt_testing#

Put the version number of your test where the # is.

Resulting in semantic suffixes for files:

  • file.txt
  • file.txt_lastworking
  • file.txt_orig
  • file.txt_testing1
  • file.txt_testing2

Isn't that pretty!

This little naming convention (lastworking, orig, testing#) will clarify a whole lot for you later (tomorrow or two years from now) without doing endless of cat, tail, head, and diff commands. Enjoy!



A Few Good Blog Posts

Clarifying the technology career landscape according to the layers of the KOS Business Architecture Canvas and the Ten Phases of Achievement
We give you on-the-ground tips to making sure you document your business processes so you can refer back to them, use them constantly, and hand them off to others.
Start imagining how it all comes together in your favor
Gurus talk about mindset because motivation is easy to discuss while skills are difficult to outline and teach.
three simple things to get people to enjoy talking to you more