Linux Blog

Tar Archive Mischief.

Filed under: Shell Script Sundays — TheLinuxBlog.com at 1:22 am on Sunday, June 1, 2008

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]




Random Man Pages:
vcsa
fs
SSL_connect
sonar

1 Comment »

Pingback by The Linux Blog » Red5 On Fedora 11 Howto

September 22, 2009 @ 9:05 am

[...] the folder you’ll have to figure out what it extracted and clean up all those files, see tar archive mischief for more [...]

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>