Having trouble uncompressing a few files

90,737

You can use the command file to determine the type of compression that was used for a particular file.

Examples

$ file file.zip 
file.zip: Zip archive data, at least v1.0 to extract

To uncompress this file, use unzip.

$ file file.rar 
file.rar: RAR archive data, v1d, os: Win32

To uncompress this file, use unrar.

$ file file.7z 
file.7z: 7-zip archive data, version 0.3

To uncompress this file, user 7z.

$ file file.tgz 
file.tgz: gzip compressed data, from Unix, last modified: Sun Oct 13 01:14:43 2013

To uncompress this file, use tar. Use the switches tar zxvf.

$ file file.tar.bz2 
file.tar.bz2: bzip2 compressed data, block size = 900k

To uncompress this file, use tar. Use the switches tar jxvf.

$ file afile.gz 
afile.gz: gzip compressed data, was "afile", from Unix, last modified: Sun Oct 13 01:10:19 2013

To uncompress this file, use gunzip.

Extensions

gunzip is one of the tools that does care what the files are named. The files need to have one of the following extensions so that gunzip can uncompress them.

  • .gz, -gz, .z, -z, or _z (ignoring case)

If you have a file that was compressed using gzip and attempt to unzip it you'll encounter this message:

$ file afile_not_named_gz 
afile_not_named_gz: gzip compressed data, was "afile", from Unix, last modified: Sun Oct 13 01:10:19 2013

$ gunzip afile_not_named_gz
gzip: afile_not_named_gz: unknown suffix -- ignored

The easiest way to fix this is to rename the file so that it has an extension:

$ mv afile_not_named_gz afile_not_named_gz.gz
$ gunzip afile_not_named_gz.gz

$ ls |grep afile_not_named_gz
afile_not_named_gz

You can also pacify gunzip by using the -S switch, and tell it the suffix (extension) if it's something other than the ones listed above.

$ gunzip -S _gz afile_not_named_gz
$

Realize that whatever you use as an extension gets stripped off by gunzip though:

$ ls -l | grep afile_not_named 
-rw-rw-r-- 1 saml saml       0 Oct 13 08:04 afile_not_named
Share:
90,737

Related videos on Youtube

John
Author by

John

Updated on September 18, 2022

Comments

  • John
    John over 1 year

    So I have to uncompress 4 different files. When I do

    file file1
    file file2
    file file3
     file file4
    

    for example, different messages are displayed. For example one starts like "gzip compressed data, …, another starts like RAR archive data, v1d, os: Unix…, another starts like compress'd data 16 bits…

    I am not really sure how to differentiate between the different uncompressing commands. Which one would I use for each?

    For those who asked, the filenames are actually file1, file2, etc. They have no visible extensions at all.

    • slm
      slm over 10 years
      Can you show the actual names of these files?
    • terdon
      terdon over 10 years
      And the actual output of the file commands?
  • umläute
    umläute over 10 years
    tar -xvf filename will only work for tar-archives. (newer versons will autodetect compressed tar-archives and use the appropriate uncompressor), but it won't work with other compressed files (e.g. file.gz) or zip archives...
  • John
    John over 10 years
    I am still a bit confused for a few of them. I have 2 files left that I need to uncompress. First off I will say that neither file has an extension, but when I "file file1" and "file file2" without the quotation marks it still shows the same messages that you have listed.
  • John
    John over 10 years
    Neither file actually has a . extension if that makes a difference. One of the messages is "file1: compress'd data 16 bits" so for this one I have tried using "uncompress file1" but it did not work. The last one I am confused with displays the message "file2: gzip compressed data, was "file2", from Unix, last modified:..." so I tried to use something like "gunzip file2" but that did not work. The message that appeared was "gzip: file2: unknown suffix -- ignored
  • slm
    slm over 10 years
    @John - extensions are typically meaningless in Linux/Unix. Files contain a header (magic number) that identifies what the files actually are. gunzip if one of the tools that does care, I'd rename the files to file1.gz and try gunzip file1.gz.
  • slm
    slm over 10 years
    @John - I've updated the answer to include some additional info on gunzip.
  • Kartik
    Kartik over 10 years
    @umläute I have tried it on my own system and it seems to work for gzip archives.
  • umläute
    umläute over 10 years
    i said zip archives (as produced by winzip and the like); i'd say that there are archives that are not necessarily produced by (or compatible to ) ar
  • Rohan Bhatia
    Rohan Bhatia about 7 years
    @slm can u please tell me the difference between the cases when we use tar -zxvf and when we use gzip command to decompress
  • Kat
    Kat almost 7 years
    @RohanBhatia, you can use gunzip on tar.gz and tgz files. Those are tar files that have been compressed with gzip. Tar is just a way to combine multiple files, since gzip only works on a single file. But if you decompress it with gzip, you'll get a tar file that still has to be unpacked. Your only option is to either use file extensions as a hint or to decompress it and then check again if it might be a tar file.