Ubuntu – Extract only the contents of an archived directory from within an archive

archivecommand lineextracttar

The Situation

I am extracting a CMS from drupal-7.15.tar.gz to /var/www.

When extracted normally (with tar -xvzf filename.tar.gz) the files end up in /var/www/drupal-7.15/

The Goal

I want the contents from the archived drupal-7.15/ directory to extract directly into /var/www

Best Answer

Use

 tar -xvzf filename.tar.gz --strip-components=1

--strip-components=1 tells tar to strip the first path component (the drupal-7.15/ in your case) from each file when unpacking.