7

I cannot use tar -tz as the solaris version I'm using does not accept the -z option.

I tried something like gunzip file.tar.gz | tar -tv but that only gives:

tar: /dev/rmt/0: No such file or directory

...and unzips the tar.gz to .tar which is undesired. I only want to look inside them without modification.

Caleb
  • 70,105
dr jerry
  • 329

6 Answers6

7

Don't have a Solaris box handy, but wouldn't something like zcat file.tar.gz | tar -tv do the trick? That might need to be gzcat or gunzip -c on Solaris, I'm not sure.

UPDATE: @Riccardo Murri points out that the default behavior of tar on Solaris is NOT to read from stdin (which seems very un-Unixish, but ce la vie), so zcat file.tar.gz | tar -tv -f - is probably what you need.

UPDATE 2: Finally found what looks to be a decent site for Solaris man pages, so I present to you man gunzip and man tar.

Hank Gay
  • 3,549
  • Thanks for your answer but.. gzcat either displays the contents of all files in the archive, or when given gzat -l it displays only the tar archive in the compressed .gz archive. What I want is really in between: a list of all the files inside the tar archive. Never thought this would be that mind bending. – dr jerry Aug 05 '11 at 13:56
  • 8
    I think gzip -dc file.tar.gz | tar -tv -f - is the correct invocation; you need the -f - to tell Solaris' tar to read data from STDIN (it's not the default as it is on many Linuxes), and you need to pass -d and -c to to gzip to decrompress to STDOUT. – Riccardo Murri Aug 05 '11 at 14:08
  • @Riccardo Murri Thanks. I didn't think about the possible differences in tar behavior, too. I'll update my answer to include the flags you mentioned. – Hank Gay Aug 05 '11 at 14:32
  • 2
    Solaris man pages are available on Oracle's website: Solaris 10, Solaris 11, other Solaris versions – Gilles 'SO- stop being evil' Aug 06 '11 at 00:23
  • @Gilles Thanks. Oracle should really do something about the fact that googling for "solaris man gunzip" doesn't bring back their pages as the very first result. – Hank Gay Aug 06 '11 at 14:47
  • 1
    The "un-Unixish" behavior is what the original V7 UNIX tar did. It defaults to reading or writing a tape. That's what the "t" stands for. – Alan Curry Aug 15 '12 at 15:46
  • c'est la vie not ce la vie (: – soyuka Jun 04 '14 at 16:03
3

The right answer if you only have the Sun version of tar is:

gzip -dc file.tar.gz | tar -tf -

as given by Riccardo Murri in a comment above. You can use that command on any version of Solaris since the dawn of day.

If you had GNU tar available then you of course wouldn't even be asking the question. I believe that on Solaris 11 that GNU tar is installed by default, however it will be called gtar to distinguish it from the standard Sun version of tar.

If GNU tar for whatever reason is not installed on your Solaris 11 system then you can install it like this:

pkg install //solaris/archiver/gnu-tar

It is somewhat ironic that GNU tar is available now in the default install on Solaris 11 because it has become much less needed : it seems Oracle/Sun has update their own tar so that it now offers compression support (similar to GNU tar) and it can handle troublesome Linux tar files that would previously give an error if you tried to untar with Sun tar.


On Solaris 10 you can hope that your SysAdmin has been kind enough to install the contents of the "Solaris Companion CD" in which case you will find GNU tar in /opt/sfw/bin/gtar. Unfortunately many Solaris SysAdmins take pride in deliberately not installing the packages from Sun (now Oracle) that make a Solaris system "GNU compatible" when they set up a host. Beats me why.

In any case : You should always have GNU tar on your system (at least on <Solaris11). Most open source packages are packaged with GNU tar and in some cases these cannot be untar'ed using Sun tar due to some differences in how symlinks are treated I believe. The opposite is never true, i.e. GNU tar can always untar a file that was created with Sun tar.

In your organisation: Make sure GNU tar is part of your default package for new Solaris hosts !

peterh
  • 922
  • On Solaris 11, even the native tar has compression support now, you don't need to force gtar. – alanc Aug 16 '12 at 04:27
  • @alanc. Thank you for this. Wasn't aware of that. I guess you learn new stuff every day. I'll test a Linux tar file known to cause problems. I'll do the test on both Solaris 10 and Solaris 11 and update my posting accordingly. – peterh Aug 17 '12 at 08:23
1

You missed the -c switch:

gunzip -c file.tar.gz | tar -tv
Sbh
  • 21
1

Try tar -tvf <filename>.tar.gz (:

Daniel Le
  • 256
1

AVFS is a virtual filesystem (based on FUSE) that allows you to see inside archives as if they were directories (amongst others). It's supported in Solaris, but I don't know if there are packages available; you may need to compile from source.

Run mountavfs once and for all (it'll persist until the next reboot; you should put it in your ~/.profile). This creates a view of the whole filesystem rooted at ~/.avfs. Inside this view, every archive has an associated directory whose name has an extra # at the end. This directory contains the contents of the archive.

mountavfs
ls -lR "~/.avfs$PWD/file.tar.gz#"
cp -p "~/.avfs$PWD/file.tar.gz#/path/to/file-to-extract" .
1

In Solaris 10, use gzip -dc target.tar.gz | tar xf - to extract, after extracting you should be able to see the directory.

Eshwer
  • 11