tar command to explore multiple layers of tar and tar.gz files

Hi all,

I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to look inside two tar files are once.

The tar file is structured as follows:

List_of_tests.tar -> These_are_the_tests folder -> several tar.gz files -> a series of folders which I want to search

So far for code I have:

PATH=`tar tf List_of_tests.tar | grep generaltest | xargs tar tf  | grep test42`

The first two commands (tar tf and grep) work correctly however I am unable to get the third command to run correctly. It tells me the directory does not exist and I believe this is because tar tf only lists what is inside that directory and therefore after executing the file the first time I lose List_of_tests.tar from the path and the path simply starts with These_are_the_tests/....

Any ideas?

Thanks!
Bashnewbee

The second tar knows nothing of the first tar so can't find the file. To get a file out of a tar you have to extract it. You can make it print to stdout with -O, and extract the other one from there:

# list files inside inside.tar.gz, which itself is inside file.tar
tar -O -xf file.tar inside.tar.gz | tar -ztf -

I don't think you can list files in file.tar and extract files from file.tar in the same call to tar, you may want to save the list to a temp file and operate on it from there.