I ran into a problem the other day when I downloaded a particular tar.gz archive (Simple Machine Forums to be specific.) The problem was that despite how good SMF might be the developers did not put the files in a folder before they tar.gz’d it. This is not the only time I have ran into this problem, a lot of developers actually do it. Over time its become a habit to assume that its in a folder.
Here’s a solution to delete all files that were extracted from an archive:
tar xvzf [filename] > [filename]-filelist.txt
cat filelist.txt | while read i; do rm $i; done;
If you want to, you can do a dry run of the script by putting an echo in front of the rm statement and looking at the output. All files that you had e.g index.php will have most likely been overwritten from the extract in the first place so, it doesn’t hurt to delete them.
Once you have deleted all of the files from the archive you can simply create a directory and use the following to extract to it:
tar xvzf [filename] -C [yourdir]