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
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:
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!