I want to see a tar.gz files that are inside a tar file.

So I have a tar file that has a tar.gz file inside and I want to see the tar.gz files without extraction my tar and my tar.gz.

So to explain more, inside my tar I have a tar.gz, File.tar -> File.tar.gz. so I need to see the files inside my tar.gz but my tar.gz is already inside my tar, and that without extracting my tar and also my tar.gz.

I tried this but doesn't work : tar -xvf File.tar File2.tar.gz | gtar -ztvf -

Can you help me with this?

  • Hello again , inside my tar I have a tar.gz, File.tar -> File.tar.gz. so I need to see file inside my tar and inside my tar.gz that is already inside my tar .
    – Issam
    Commented Jan 3, 2017 at 11:00
  • It might help to use example filenames. As it stands, your explanation is not the clearest. Commented Jan 3, 2017 at 11:17
  • I have this file . File.tar inside this file you can find a file.tar.gz and other files , when I do a tar -tvf File.tar , I can see all the files : exemple : File1 and File2.tar.gz but I want to see the files inside File2.tar.gz . I know I can do something like tar -xvf File.tar -O File2.tar.gz.
    – Issam
    Commented Jan 3, 2017 at 11:23
  • Or something like that
    – Issam
    Commented Jan 3, 2017 at 11:24
  • Or I need to make a pipe or an exec.
    – Issam
    Commented Jan 3, 2017 at 11:25

5 Answers 5


You'll need to run tar -tf /path/to/file.tar.gz, or tar -tzf /path/to/file.tar.gz.

As far as I've seen, you should avoid using -tf, and prefer -tzf: at least on BSD systems, forgetting the z gives:

tar: input compressed with gzip; use the -z option to decompress it

Following up on your comment, say you want to list the content of an archive inside an archive, ... Try this:

tar -zxOf /path/to/parent/archive.tar.gz path/to/packed/archive.tar.gz | tar -ztf -

With path/to/packed/archive.tar.gz, the path of your archive inside /path/to/parent/archive.tar.gz.

  • Doesn't work : and my parent package archive is a tar only not a tar.gz.
    – Issam
    Commented Jan 3, 2017 at 14:55
  • The option -O usually switches to old tar archive versions. You do not seem to speak about tar but probably about gtar.
    – schily
    Commented Nov 29, 2018 at 9:49
  • The -O option is about writing tar output to stdout. My answer is about tar, the same you would find on BSD systems. The tf/tzf comment is however about gtar specifics, pointing out they are not standard thus should be avoided.
    – SYN
    Commented Mar 20, 2021 at 22:40

There are many solutions you can use the command

tar -tvf filename.tar.gz

You can also use vim

vim filename.tar.gz
  • vi and it's clones do not support to edit binary files without destroying the content and a compressed tar archive is heavily binary.
    – schily
    Commented Nov 29, 2018 at 9:50

vim fnm.tar.gz or vim flnm.tgz tar -tvzf fnm.tar.gz or tar -tvzf flnm.tgz

Both of these will help display the contents in the file. If you have a tar file inside of another tar file then thats a bit tricky.


_ for 1 level of taring _

a portable solution to uncompress 'on the fly' and then have tar display the content:

gzip -dc - <file.tar.gz | tar tvf -

this is the pendant of the compression on the fly:

tar cf -  files and dirs | gzip -c - >newcompressedtarfile.tar.gz

(of course, with a recent (and usually GNU variant) tar you can just: tar tzvf file.tar ... but the way above is portable, and can be generalised to many other scenarios (find infos inside files without ungzipping them first, etc)

_ for you case: list the content of a .tar.gz that is inside a .tar _

You will probably need the GNU version of tar and use the --to-stdout (or Capital O, -O) optino to uncompress a file to stdout instead of creating it on disk:

# let's say Archive.tar contains file.tar.gz, 
{and you want the content of the latter without writing any files on disk

tar -xOf  archive.tar  file.tar.gz | gzip -dc - | tar tvf -
  • I can't do something like this : <code> tar -xvf File.tar | gtar File2.tar.gz | tar -tvf - </code>?
    – Issam
    Commented Jan 3, 2017 at 12:04
  • I have this error : tar: illegal option -- O
    – Issam
    Commented Jan 3, 2017 at 15:33
  • The -O parameter is used only with tar.gz files not with a tar file.
    – Issam
    Commented Jan 3, 2017 at 16:31
  • @Issam : you specified Linux, so usually GNU tar, which should know -O (not for compressed files, that was the z option which I just edited out as the first tar file is not .gz). Commented Jan 3, 2017 at 17:20
  • The -O work for my tar.gz but not for my tar maybe because I am in Aix
    – Issam
    Commented Jan 3, 2017 at 17:51

Gnu tar has "--to-command'

tar xzf tarfile1.tar.gz pathto/tarfile2.tar.gz --to-command='tar tvzf -'

Anyway "-O" also works for you :

tar xzf tarfile1.tar.gz pathto/tarfile2.tar.gz -O | tar tvzf -

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .