Extracting a tar archive, advanced!

Because oth­er­wise I’ll for­get 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 con­tains an upgraded ver­sion of a pop­u­lar blog­ging soft­ware suite.  The con­tents of the archive look like this:

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

Let’s also sup­pose, shall we, that you’ve got the pre­vi­ous ver­sion of foo already installed in another loca­tion, like /var/www/foo.example.com/  , and you want to extract the con­tents of the archive (here’s the impor­tant part) into that direc­tory, with­out hav­ing to move the direc­tory con­tents or rename any direc­to­ries, or what­not.  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/).

Leave a Reply

Switch to our mobile site