LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-23-2004, 11:11 PM   #1
leontini
Member
 
Registered: Aug 2003
Location: Melbourne, Australia
Distribution: Fedora Core 8-10
Posts: 61

Rep: Reputation: 15
How to list contents of a .tar.gz without unzip?


Hey all,

Does anyone know how to list the contents of a .tar.gz, without first uncompressing? using gzip only reports back the foo.tar, and tar doesn't recognise foo.tar.gz as a valid tar archive.

Can this be done? It could save me a lot of time uncompressing big tar's full of data to find the right file.

Thanks in advance,

Justin
 
Old 03-24-2004, 12:06 AM   #2
comp12345
Member
 
Registered: Feb 2004
Posts: 467

Rep: Reputation: 30
use the -t option
 
Old 03-24-2004, 12:54 PM   #3
bhaskie
Member
 
Registered: Jan 2004
Location: New Delhi, India
Distribution: L.F.S 5.0 | FreeBSD 5.2 | Debian sid | Gentoo 2004.0 | Slackware 9.1
Posts: 78

Rep: Reputation: 15
Using just the -t option wont show the contents of tar.gz or tar.bz2 archives. You have to filter them further thru gzip or bzip. For example, to see the contents you will do:
for tar file: tar -tvf foo.tar
for gzip file: tar -ztvf foo.tar.gz
for bz file: tar -jtvf foo.tar.bz

Check it out for yourself!
 
Old 03-24-2004, 03:27 PM   #4
Wynd
Member
 
Registered: Jul 2001
Distribution: Slackware 12
Posts: 511

Rep: Reputation: 32
less foo.tar.gz
 
Old 03-24-2004, 03:36 PM   #5
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
Midnight Commander will let you browse the contents of an archive as if it were a directory (in a sense...it actually just extracts it to a temp directory).
 
Old 03-24-2004, 03:46 PM   #6
bhaskie
Member
 
Registered: Jan 2004
Location: New Delhi, India
Distribution: L.F.S 5.0 | FreeBSD 5.2 | Debian sid | Gentoo 2004.0 | Slackware 9.1
Posts: 78

Rep: Reputation: 15
Quote:
Originally posted by Wynd
less foo.tar.gz
This will only show junk on the console. He wants to display the list of files in the tarball. Not the binary contents!
 
Old 03-24-2004, 07:45 PM   #7
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
Quote:
Originally posted by bhaskie
Using just the -t option wont show the contents of tar.gz or tar.bz2 archives. You have to filter them further thru gzip or bzip. For example, to see the contents you will do:
for tar file: tar -tvf foo.tar
for gzip file: tar -ztvf foo.tar.gz
for bz file: tar -jtvf foo.tar.bz

Check it out for yourself!

...

This will only show junk on the console. He wants to display the list of files in the tarball. Not the binary contents!
So....I win?
 
Old 03-24-2004, 08:11 PM   #8
bhaskie
Member
 
Registered: Jan 2004
Location: New Delhi, India
Distribution: L.F.S 5.0 | FreeBSD 5.2 | Debian sid | Gentoo 2004.0 | Slackware 9.1
Posts: 78

Rep: Reputation: 15
Quote:
Originally posted by mikshaw
So....I win?
Please dont confuse other members. You concatenated two of my posts showing that I am contradicting myself!
I wasnt contradicting my original post. That's the simplest way to do it. I was saying doing a
Code:
less foo.tar.gz
will throw junk on the screen.
Of course, mc is very convenient to browse thru tarballs. I do agree with u on that. But doing a
Code:
tar -ztvf foo.tar.gz
or
Code:
tar -jtvf foo.tar.bz2
displays the same without the need of installing mc.

Regards,
Bhaskar.
 
Old 03-24-2004, 09:41 PM   #9
leontini
Member
 
Registered: Aug 2003
Location: Melbourne, Australia
Distribution: Fedora Core 8-10
Posts: 61

Original Poster
Rep: Reputation: 15
bhaskie,

You are a legend! Thanks, a very simple and well explained solution, that is already saving me time.
 
Old 03-24-2004, 09:59 PM   #10
fancypiper
LQ Guru
 
Registered: Feb 2003
Location: Sparta, NC USA
Distribution: Ubuntu 10.04
Posts: 5,141

Rep: Reputation: 60
How could someone resist the temptation to install Midnight Commander and why should they??????
An Introduction to the Midnight Commander
Midnight Commander home page
 
Old 03-25-2004, 04:11 AM   #11
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
Quote:
Originally posted by bhaskie
Please dont confuse other members. You concatenated two of my posts showing that I am contradicting myself!
Sorry...I was just being silly. You pointed out the shortcomings of the other two suggestions, but no flaw in mine....so naturally I'd assumed that I won
 
Old 03-25-2004, 04:25 AM   #12
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

Rep: Reputation: Disabled
Quote:
Originally posted by fancypiper
How could someone resist the temptation to install Midnight Commander and why should they??????
And why should I weld myself to "DOS" tools ?
 
Old 03-25-2004, 01:24 PM   #13
bhaskie
Member
 
Registered: Jan 2004
Location: New Delhi, India
Distribution: L.F.S 5.0 | FreeBSD 5.2 | Debian sid | Gentoo 2004.0 | Slackware 9.1
Posts: 78

Rep: Reputation: 15
Quote:
Originally posted by mikshaw
Sorry...I was just being silly. You pointed out the shortcomings of the other two suggestions, but no flaw in mine....so naturally I'd assumed that I won
Hey relax! I get your point.It was just that someone reading the post will get the idea that the command I suggested will throw junk at the screen. I didnt want anyone to get a wrong idea. That's all.

Now that you want me to prove that my method is subtler and simpler than yours, here's my answer!

MC (midnight commander) creates a temp directory in /tmp as /tmp/mc-root (assuming you are root). So if you click on a tarball in mc, it extracts the tarball to that temp directory. Thus you get to view the contents of the archive.
Now that is ok for a small archive. Imagine what's goin to happen when you click on the kernel sources tarball or some other archive >100MB. Thats goin to take a really long time. You can click on a tarball in MC and open a console, check in /tmp/mc-<username>/<som_folder>/some_file. Do a "file foo" on that file and it will show a tar archive.

Also, this defeats the main purpose of this thread.

Quote:
Originally posted by leontini

How to list contents of a .tar.gz without unzip? ( post #1)
Hey all,

Does anyone know how to list the contents of a .tar.gz, without first uncompressing? using gzip only reports back the foo.tar, and tar doesn't recognise foo.tar.gz as a valid tar archive.

Can this be done? It could save me a lot of time uncompressing big tar's full of data to find the right file.
The guy asked a method to view contents of an archive without decompressing. MC no doubt is good but defeats the purpose! Why not keep it simple?

P.S. I am not trying to start a war here. Just helping out fellow linuxers.

Regards,
Bhaskar.
 
Old 03-25-2004, 03:58 PM   #14
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
Quote:
Imagine what's goin to happen when you click on the kernel sources tarball or some other archive >100MB. Thats goin to take a really long time.
Very true....I see your point.
 
Old 04-21-2010, 02:07 AM   #15
nagakiran
LQ Newbie
 
Registered: Apr 2010
Posts: 1

Rep: Reputation: 0
Hi,

tar -ztvf file.tar.gz
lists only the top-level directories & files. Is there a way to list the contents of a tar file recursively.

I need to analyze the disk space used across the directory structure
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
D/l a .tgz.tar file..how to unzip Navop Linux - Newbie 1 03-13-2005 07:56 AM
How to unzip a tar.gz?? abort...retry Linux - Newbie 3 01-02-2005 08:08 AM
How to Unzip tar.gz Files in Redhat 7.2 newbie2linux Linux - Newbie 8 12-03-2003 08:59 PM
Why can't I unzip a .tar.gz file Dewar Linux - Software 8 09-18-2003 04:07 PM
unzip a tar.gz file klfreese Linux - Newbie 1 07-22-2003 11:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration