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
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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.