Detect compression type of a file
Use the file command first to get info about the possible compression. A tar archive has the filenames included in it at the top. You can determine that it is likely to be one of those formats by looking at the first few bytes. You should then test to see if it really is one of those, using an integrity check from the associated utility for that format, or by actually proceeding to decompress. ...