Linux/solaris when to use tar or gtar

linuxsolaristar

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 ?

Best Answer

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'.