I need to findout type (compress method) of archive in parametrs when call to my script and accord to compress method use tar with right options.
I find that file command return information about file so I can get 2nd column from that and use some condition and check what is it (I just need support tar -compressed by gzip or bzip2 not compressed and zip but I shouldn´t check by postfix but by content).
So i want to ask if there is better way to get compressed method of archive then by file and getting 2nd column. Thanks
Your best choices are to either depend on
fileas you are now, or to look up the likely magic numbers (file type identifiers generally placed at the beginning of a file) and figure it out yourself.For example, ZIP files start with “PK” and BZip2 files start with “BZ”. These magic numbers may be longer, but that’s what I noticed when looking at a couple a moment ago.