7

How To List Files Within tgz (tar.gz) Archives


Posted by Artem Russakovskii on April 26th, 2008 in Linux

This may not be very obvious but this is the command line to list files within a tar.gz archive on the fly:

1
tar -tzf file.tar.gz

-t: lists files
-f: instructs tar to deal with the following filename (file.tar.gz)
-z: informs tar that the it's dealing with a gzip file (-j if it's bzip2)

● ● ●

Artem Russakovskii is a San Francisco programmer, blogger, and future millionaire (that last part is in the works). Follow Artem on Twitter (@ArtemR) or subscribe to the RSS feed.

In the meantime, if you found this article useful, feel free to buy me a cup of coffee below.



Share
  • sunny

    thanks !!!!

  • clive

    How can I list the contents of multiple archives within a folder? Have tried;
    for i in *; do if [ -d "$i" ]; then tar tzvf "$i".tar.gz "$i" >> tar.gz-list.txt; fi; done
    but this does not work.
    Any suggestions?

    • http://beerpla.net Artem Russakovskii

      This is how I would do it:

      find . -name "*.tgz" -exec tar tzf {} \; > list.txt

      Just tried it and it works fine (adjust it for your own extention – I used tgz).

  • clive

    Artem Russakovskii says:
    November 5, 2010 at 10:05 am

    This is how I would do it:

    find . -name "*.tgz" -exec tar tzf {} \; > list.txt

    Thanks Artem, I'll give it a go and them try to understand the code layout.

  • clive

    The code you supplied worked, thanks. If I wanted the text to appear in the terminal window as well as being piped to a text file should I add a verbose flag to the tar command? For example;
    find . -name "*.tgz" -exec tar tzvf {} \; > list.txt

    • http://beerpla.net Artem Russakovskii

      No, that won't work – look up the usage of 'tee'

  • Carl W.

    Very helpful, thank you!