Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I untar a subdirectory into the current directory? [closed]

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

Example, the 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 do I extract everything under wordpress/ into the current directory? In otherwords, it will not create a wordpress directory.

I've tried this with no luck:

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

I know I can extract it normally and move it back, but I figure there has to be a way to do it in one shot.

like image 604
Cory R. King Avatar asked May 10 '09 16:05

Cory R. King


People also ask

How do you move the current directory in Linux?

To move a file or directory from one location to another, use the command mv. Common useful options for mv include: -i (interactive) — Prompts you if the file you have selected overwrites an existing file in the destination directory. -f (force) — Overrides the interactive mode and moves without prompting.


1 Answers

Why don't you untar normally, then just:

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

But alas, there's:

tar --strip-components=1 -zxvf wordpress.tgz 
like image 63
kch Avatar answered Sep 24 '22 23:09

kch