When you need to be rough with your data–change a bunch of files at once…and you might not do it right the first time. Or you need to recover something that grew a few bad sectors and you only have a bits of your file left. Do you have to restore ALL your work? How do you see where the changes are?
Let’s step thru a partial restore using tar and diff. For example, say I have a code directory that I’ve damaged with a regular expression. My work is in /home/work, my backups are in /home/backups.
I “untar” the backup in a temporary directory next to the work directory like so:
$ cd /home/ $ mkdir restore $ cd restore $ tar xzf /home/backup/monday.tgz $ cd /home
With the two directory trees next to each other, finding the differences is easy. The -r switch for diff tell us to search an entire directory tree, and the -q switch tells diff to display a brief description of just file names. (Diff will work on binary files, so this command will also work on graphics and audio files, just don’t forget the -q).
$ diff -qr /home/work /home/restore Files /home/work/lib/BugCatcherHelper.java and /home/restore/lib/BugCatcherHelper.java differ Files /home/work/lib/BugCatcher.java and /home/restore/lib/BugCatcher.java differ
This example is obviously contrived, and often what source control should be used for, but not everyone uses source control.