How to unzip a subdirectory into the current directory?

How to extract a subdirectory in tarball to the current directory?

Example tarball from wordpress :

wordpress/ wordpress/wp-trackback.php wordpress/wp-config-sample.php wordpress/wp-settings.php wordpress/wp-rss2.php wordpress/readme.html wordpress/index.php ... 

How to extract everything in wordpress/ to the current directory? In other words, it will not create the wordpress directory.

I tried this with no luck:

 tar xvfz latest.tar.gz wordpress -C ./ 

I know that I can retrieve it normally and move it back, but I suppose there should be a way to do this in one shot.

+45
command-line unix tar
May 10 '09 at 16:14
source share
2 answers

Why don't you figure it out fine, and then just:

 mv wordpress/.* . mv wordpress/* . rmdir wordpress 

But, alas, there are:

 tar --strip-components=1 -zxvf wordpress.tgz 
+80
May 10 '09 at 16:19
source share

Surprisingly, my tar (GNU tar v1.16) does not have the ability to split the original elements of the path.

However, it seems that in later versions there is a parameter --strip-components=number , which will separate many components from the beginning of the path.

If you, like me, use an older tar and you are sure that there is no directory or file named wordpress/wordpress in the archive, you can always just make a symbolic link from wordpress to . , then extract as usual:

 ln -s . wordpress tar xvfz latest.tar.gz wordpress rm wordpress 
+6
May 10 '09 at 16:30
source share



All Articles