2

is it possible to know when need to use tar or gtar according to tar file

for example

I have some tar file as

    sometarfile.tar

how to know if need to use tar or gtar command ?

is it possible to check the tar file and according this to understand which command to run ?

yael
  • 2,433
  • 5
  • 31
  • 43

1 Answers1

3

No, the tar file format stores no information about the program that generated it.

EDIT:

Linux versions of the file utility can detect the difference between Solars and GNU tar generated files. It does this by extending the search to include the format and version information in the header. GNU generated tar files have ustar (thats 2 spaces after ustar) whereas Solaris tar files have ustar 00.

You can make your Solaris version of file work in a similar manner to the linux one by adding the line

257    string        ustar\040\040    USTAR tar archive (GNU) 

above the line

257    string        ustar    USTAR tar archive

in /etc/magic. Having said that I don't know and can't find a standard for encoding the version information so I would assume it's a hack that can't be relied on.

I can't say I've ever found a tar file that GNU tar couldn't handle that the Solaris tar could (the reverse is as you know not true) so in your situation I would just use gtar to extract files from any tar file you have.

Regarding your question in the comments. That's not a great idea as an exit status >0 just means an error occurred which may be an error other than 'I don't understand this format'.

user9517
  • 115,471
  • 20
  • 215
  • 297
  • Well my Linux 'file' command does (possibly with some ugly magic) see the difference: "suntest.tar: POSIX tar archive" and for GNU: "gnutest.tar: POSIX tar archive (GNU)" – basvdlei Jun 05 '12 at 07:31
  • @basvdlei Yes, but the Solaris file command (up to Solaris 10) can't differentiate them it just says they are both USTAR tar archives. – user9517 Jun 05 '12 at 07:32
  • @lain I think I have solution first I use tar and if its fail (exit code diff from 0 ) then I use gtar - what you think? – yael Jun 05 '12 at 07:38
  • @yael: see my edit. – user9517 Jun 05 '12 at 10:25
  • @lain OK so gtar in solaris replace the tar command and gtar is fit for all tar files in solaris ( I mean what tar command do gtar do the same ) - am I right ? – yael Jun 05 '12 at 11:34
  • No - Solaris can generate a tar file that GNU tar cannot read correctly. See [this question](http://serverfault.com/questions/436110/issues-while-untaring-in-linux-tarball-created-from-solaris/569030#569030). – Nomic Jan 23 '14 at 00:15