To list an archive's contents I can do :

tar -tzvf mytarball.tar.gz

But this works for local files only. Can someone point out how to do it (if at all possible) for files over internet.

I tried it with a file

wget -q https://git-core.googlecode.com/files/git-1.8.0.tar.gz | tar -tzv

But gives

gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now

So does tar work properly with streams for listing ? Are there any compression formats which allow this (without requiring to download the whole file) ?


Your command would work, if you told wget to output the downloaded file to stdout rather than a file:

wget -q -O /dev/stdout http://… | tar -tzv

However, it will require downloading the whole file, at least for Tar and Zip archives. The Zip format puts its "directory" at the very end; meanwhile, Tar does not have a single directory and just has a linear stream of header+data pairs, so filenames are scattered everywhere.

(There certainly should be archive formats that can be listed this way, but I don't know the exact details of any other format out there.)


Edit: It is not possible to list the contents of a file over the internet, unless the server has an API or something to process the file and output the results. You should download the file locally and then process the file.

This should work.

wget -q https://git-core.googlecode.com/files/git-1.8.0.tar.gz && tar -tzvf git-1.8.0.tar.gz

A part from http://www.cyberciti.biz/faq/list-the-contents-of-a-tar-or-targz-file/

List the contents of a tar file

$ tar -tvf file.tar

List the contents of a tar.gz file

$ tar -ztvf file.tar.gz

List the contents of a tar.bz2 file

$ tar -jtvf file.tar.bz2

You can use:

wget -qO- https://git-core.googlecode.com/files/git-1.8.0.tar.gz | tar -xvz

The file will be downloaded, unpacked, and the screen will show the files.

But if you want make a file Request a and does not save it, use:

wget -q -O- https://git-core.googlecode.com/files/git-1.8.0.tar.gz | tar -xvz

enter image description here

  • What is the difference between your two command lines? I can’t find any. – erik Mar 10 '14 at 21:21

Alternatively if you can run shell code on the remote host:

ssh remotehost 'tar -tzvf mytarball.tar.gz'

  • This has the benefit of requiring virtually no network transfer aside from the text listing of contents. – Ram Mar 10 '14 at 20:11

To redirect http data output from file to stdout you need to use -O switch, then you can grab it

wget -q https://git-core.googlecode.com/files/git-1.8.0.tar.gz -O - | tar -tzv

But still why you do this? Tar doesn't have file list, so like that you download full file to get file list, and one more time you will need to download full file to get wanted files. So if you plan to get some files from that tar.gz, better is to save it and delete it after.

The only good thing about this is to get file list for some indexing. For remote file list ZIP files are much better but still you can't download them using wget.

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.