0

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
0
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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