Given a gzip compressed file, how do I know what compression level (1-9) was used for it?
4 Answers
It is stored in the header of file. To see it, use file command. For example:
$ file testfile.gz
testfile.gz: gzip compressed data, from Unix, last modified: Sun Sep 15 14:22:19 2013, max compression
Unfortunately there are only three possible values in the header: max speed (level 1), max compression (level 9) and "normal" (all other levels). But better than nothing!
- 441
There is no way to directly determine gzip level .
The only way to determine it in my opinion is to gunzip the file and compressing it at different levels and then comparing the results with your existing file size.
I believe the default level is 6 so in most cases that should be your answer
- 5,069
-
-
3
-
2Python also defaults to a compression level on 9: https://docs.python.org/3/library/gzip.html – RFox Feb 15 '16 at 14:28
-
1
-
nginx defaults to level 1 by the way. https://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip_comp_level – Quoting Eddie Jun 11 '22 at 06:17
-
@AndrewLambert Source for that information? I tried GNU tar 1.34 on Debian Bookworm and in the git shell for Windows. Both default to -6. Also confirmed by https://superuser.com/a/305134/165722 – jlh Dec 11 '23 at 10:44
gzip -l <filename> will give you the compression ratio, but there's no way of directly finding the compression level used.
- 7,665
-
2While the assertion about elvel is false, the command is useful for comrpession ratio. – mveroone Oct 19 '15 at 13:04
There is no direct way of knowing it. It most probably 6 (the current default) or 9 (the best compression). you need to try and compare.
See https://stackoverflow.com/questions/16153334/how-to-determine-the-compression-level-of-deflate
- 357
filecan recognise those). A 10^7 bytes file still only resulted in 7 unique outputs - partitioned (1,2,3,4,5678,9). While this doesn't mean different levels are useless for bigger files, it shows you can't assume 9 unique outputs. – valid Nov 10 '15 at 03:38fileonly showsgzip compressed data. – bluenote10 Apr 08 '22 at 19:23