How to uncompress a .bin.gz file?

I have a file named like file.bin.gz.

I tried using gzip -d f.bin.gz to uncompress it, and got a .bin file.

Is the correct way to uncompress .bin files to use gzip -d? Also, .bin is a binary file, right?


Solution 1:

Yes, what you did was one of the correct ways. To un-gzip a .gz file, use gunzip or gzip -d.

If your gzipped file is file.bin.gz, you can decompress it with:

gunzip file.bin.gz

This decompresses it to file.bin. If the operation succeeds, the original file.bin.gz is automatically removed. This is to say that the gzipped file is replaced with the decompressed file.

If you want to keep the original, pass the -k/--keep flag:

gunzip -k file.bin.gz

gzip behaves like gunzip when it is invoked with the -d/--decompress/--uncompress flag. So this works too:

gzip -d file.bin.gz

As with gunzip, the default behavior of gzip -d is to replace its input file once it succeeds. You can pass both -d and -k if you want to keep the input file.

(All of this applies regardless of what kind of file you want to decompress; none of it is specific to the file having .bin in its name--that's just part of the example I've used, to better match your situation.)

You can run man gunzip for more information, or gunzip --help for a summary of options.


As for what the .bin in the filename is likely to mean, you have surmised correctly that a file named .bin is usually a binary file. However, there are several different kinds of files that are sometimes named this way and, furthermore, the vast majority of binary files do not have .bin in their names.

To get more information about what file.bin is, run file on it:

file file.bin

(This is not specific to file.bin having file in its name. In general for a file abc you can learn about what kind of file it appears to be by running file abc.)

(This is also not specific to the .bin part of the filename having Any Meaning At All)

Solution 2:

If you really need to identify the type of file you can use the file program after decompressing:

file file.bin

will consult a database looking for known markers of file types (like the string '' or 'GIF89a') and output what kind of file it thinks it is. As stated before, sometimes programmers will use .bin to disguise a standard file type by just changing the extension.