Extracting a tar archive, advanced!

 Extracting a tar archive, advanced!  General  Comments Off on Extracting a tar archive, advanced!
Oct 132009
 

Because otherwise I’ll forget and have to search through forum posts to find it again:

Let’s say you have a tar archive, foo.tar.gz .  Let’s also say that this archive contains an upgraded version of a popular blogging software suite.  The contents of the archive look like this:

foo/index.php
foo/image.jpg
foo/css/web.css
foo/css/print.css

Let’s also suppose, shall we, that you’ve got the previous version of foo already installed in another location, like /var/www/foo.example.com/  , and you want to extract the contents of the archive (here’s the important part) into that directory, without having to move the directory contents or rename any directories, or whatnot.  Here’s how:

cd /var/www/foo.example.com && tar zxvp –strip-components=1 -f /path/to/foo.tar.gz

This will extract the archive, and ignore the first level of the path (in this case, foo/).