How To List Files Within tgz (tar.gz) Archives
| Share |
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.
beer planet is a blog about technology, programming, computers, and geek life. It is run by Artem Russakovskii - a local San Francisco geek who is currently pursuing his own projects and regularly enjoys hacking Android, PHP, CSS, Javascript, AJAX, Perl, and regular expressions, working on Wordpress plugins and tools, tweaking MySQL queries and server settings, administering Linux machines, blogging, learning new things, and other geeky stuff.
thanks !!!!
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?
This is how I would do it:
find . -name "*.tgz" -exec tar tzf {} \; > list.txtJust tried it and it works fine (adjust it for your own extention – I used tgz).
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.
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
No, that won't work – look up the usage of 'tee'
Very helpful, thank you!