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 have .tgz archive i'm trying to locate a directory within it to extra how do i search within a .tgz i tried the following below but no luck.

tar -tzf archive-9.tgz | grep '161519' | xargs tar -Oxzf archive-9.tgz | grep -B 3
share|improve this question

1 Answer 1

up vote 2 down vote accepted

Would it not be easier all in one go?

tar -xzvf <tar-file-name>.tgz --wildcards "*/<directory-name>/*"

I think the reason it appears not to work with xargs is that your grep will find the directory first (pass it on and tar with extract it all) then grep will continue with the contents (pass it on and tar will fail to find those files since it has already extracted them). But this is only a guess.

share|improve this answer

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.