Uninstalling tarballs
Posted Sun Jun 18 00:57:00 -0500 2006
If you've ever downloaded a tarball (tar or tar.gz file) from the web and confidently expanded it with commands like
$ cd /usr/local
$ tar -xzf /path/to/file.tar.gz
... and then realised that actually you didn't mean to do it, you may be glad to know that there's a way to reverse it. The problem, of course, is that you've put a lot of new files into various places into an existing file tree (in this case /usr/local) that you don't want to obliterate en masse. The solution looks like this:
$ cd /usr/local
$ rm -d `tar -tzf /path/to/file.tar.gz | tail -r`
This will remove the files and directories created by the untarring operation in the reverse order. Importantly, it will not delete any directories under /usr/local that were not created above. The only potential problem is that any files were overwritten by the original untarring operation will be deleted, which may potentially break something in some cases. (To avoid overwriting files in the first place, you can give tar the -k option.)
