0

I've got this file structure:

tree .           
.
├── AAA
│   ├── a1.txt
│   ├── a2.txt
│   └── a3.txt
├── AAA.tar.gz
├── BBB
│   ├── b1.txt
│   ├── b2.txt
│   └── b3.txt
├── BBB.tar.gz
├── CCC
│   ├── c1.txt
│   ├── c2.txt
│   └── c3.txt
├── CCC.tar.gz
└── tar_test.tar.gz

Listing archive correctly shows:

tar tf tar_test.tar.gz
AAA.tar.gz
BBB.tar.gz
CCC.tar.gz

But my attempts to list inner archives fail...

tar xfO tar_test.tar.gz | tar ztf -
AAA/
AAA/a1.txt
AAA/a3.txt
AAA/a2.txt

What do I need to change to have:

tar [magic1] tar_test.tar.gz | tar [magic2]
AAA/
AAA/a1.txt
AAA/a3.txt
AAA/a2.txt
BBB/
BBB/b1.txt
BBB/b3.txt
BBB/b2.txt
CCC/
CCC/b1.txt
CCC/b3.txt
CCC/b2.txt

Thank you!

2

Your tar ztf - expects just one archive. You need one such process per archive. This can be done with --to-command option of the leading tar:

tar xf tar_test.tar.gz --to-command='tar ztf -'

From man 1 tar:

--to-command=COMMAND
Pipe extracted files to COMMAND. The argument is the pathname of an external program, optionally with command line arguments. […]

The trick is each single file extracted by the leading tar will be piped to its own separate instance of COMMAND. This way you run as many tar ztf - processes as needed.

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.