Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to extract a specific directory from the wordpress tarball. specifically wp-includes to .. It appears that the directory structure inside the tarball is wordpress/wp-includes but I just need./wp-includes once it's been extracted, no leading wordpress directory. How would I do this?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

To extract a specific directory (and its contents, recursively), just pass it as an extra argument on the command line. With GNU tar, you can strip a leading directory with the --strip-components option (and more generally transform the file names with --transform). On non-Linux systems, you can use pax (it's in POSIX, but some Linux distributions omit it from their default installation) and its -s option.

tar xf foo.tar --strip-components=1 wordpress/wp-includes  #GNU tar
pax -r <foo.tar -pp -s '!^wordpress/!!' wordpress/wp-includes

You can merge the inclusion list with the rewriting rules by appending a rule to rewrite everything to the empty name (which means “don't extract”; the rule only applies if the previous rules didn't match).

pax -r <foo.tar -pp -s '!^wordpress/\(wp-includes/\)!\1!' -s !.*!!
share|improve this answer

Assuming you have GNU tar, you can use --strip-components:

$ tar xaf tarball.tar.gz --strip=1 wordpress/wp-includes

I believe current versions of BSD tar also support --strip-components. In the worst case, you could do:

$ tar xzf tarball.tar.gz wordpress/wp-includes
$ mv wordpress/wp-includes .
$ rmdir wordpress
share|improve this answer
    
I ended up doing the latter just because in a hurry, but good to know the former exists. –  xenoterracide Nov 5 '10 at 11:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.