Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 ?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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

share|improve this answer
    
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 5 '12 at 7: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. –  Iain Jun 5 '12 at 7: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 5 '12 at 7:38
    
@yael: see my edit. –  Iain Jun 5 '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 5 '12 at 11:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.