1

I am writing unit tests for some code and found that a simple gzip is causing a difference in my results. Upon further investigation I found that gzip gives a different .gz file than gzip -c does. Why is this?

$ echo "foo" > bar
$ gzip bar
$ zcat bar.gz | gzip -c > test.gz
$ cmp bar.gz test.gz 
bar.gz test.gz differ: byte 4, line 1
$ stat bar.gz | grep Size
  Size: 28          Blocks: 0          IO Block: 4194304 regular file
$ stat test.gz | grep Size
  Size: 24          Blocks: 0          IO Block: 4194304 regular file
$ zcat bar.gz > foo1.txt
$ zcat test.gz > foo2.txt
$ cmp foo1.txt foo2.txt 
$ echo $?
0 
1
  • BTW, there no any point to use -c option if you piping to gzip. man gzip: If no files are specified, or if a file name is "-", the standard input is compressed to the standard output.
    – Alex
    Aug 21, 2018 at 21:43

1 Answer 1

4

gzipping a file will cause the original filename to be stored as part of the output header.

(By default, the modification time is stored as well, so even two identically created .gz files will differ.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .