It has been a long time since a post in this blog. I thought to break this silence with a short post.
Several text editors in Linux environment like KWrite and GEdit that will store automatic temporary files ending with a ~ (tilde) character. Generally it is a default setting in most of the major distributions. Initially this feature annoyed me, as now you have twice the number of files in your directory, and often used rm *~ to clear out the files. Although it was annoying at the beginning, there are several cases it saved me.
The ~ files store the last saved content of a text file. There are a few occasion when I copied some text or code from a different file and pasted it over the file on which I am working and save the file as a result of muscle memory. Then almost immediately I noticed that I actually had to paste the text in some other file and not the one I just overwrote. There were at least twice I faced this kind of trouble and was saved with the ~ file.
Next scenario is even worse. I wrote several classes in Java with the .java extension and compiled them into classes, which had .class files. I do not always version management tools for relatively small tasks, and manually take backups. When I made sure that the program I wrote was working fine, I wanted to clear the .class files from the directory. But, somehow, what I executed was: rm *.java.
Why I did this? Because the naming confused me from the very beginning of learning Java. The files in which we write the classes are named .java, and the compiled classes are named .class which are actually the program runnable in the JVM using the java program. I think this confusion is to blame for this.
After the removal, I almost immediately realized the catastrophic situation. Next things came to my mind is TestDisk. When I went back to the directory view in the graphical file browser (Dolphin), I saw the .class~ files sitting there. That was one wonderful moment of relief. I knew that no major changes were done between the last two saves, mostly minor comment additions have gone in. I copied the ~ files and the day was saved.
Yet another situation I faced two days back. I had a Perl script which reads the standard output and parses some numbers in a certain format and then display the mean, standard deviation, min and max (don’t ask me why I did this kind of work in Perl). I was redirecting another program’s output to this script to get the overall stats. At some point of time I wanted the output of my main program to be dumped into a file. I pressed the up key to recall the last command, which has the output from the main program to the Perl script piped in, then removed the | character and typed in >. Before I changed the file name, I pressed enter, muscle memory. And there you go, my script overwritten. Now, it is not that a big deal to rewrite the script, may be an additional 5 mins, but this would shifted my workflow and focus from the main thing I was doing, and it could have been a serious too. This time also, the day was saved. I copied the .pl~ file and restored the original. In this case two the last two saves did not have much difference.
There are some more examples I believe, but this is was I can remember now. Although I have some other horror stories, which I might share later.
Conclusion: Respect the ~ files.