I want to perform a series of recompressions of compressed files to study their properties.
At first, I tried simply recompressing
.zip files in a loop:
for f in $(seq 1 100) do zip $f.zip -9 -v $(($f-1)).zip done
Starting from a fixed
0.zip file, I noticed that, if I re-ran these lines, all but the first few files had different sizes. After some investigation, I realized this was caused by the timestamps of the compressed files. I then reset the timestamps before recompressing:
for f in $(seq 1 100) do touch $(($f-1)).zip -t 200101010101 zip $f.zip -9 -v $(($f-1)).zip done
And this time I got deterministic results for the compression using
zip. However, using
tar with the
gzip algorithm still does not work. Each time I run:
for f in $(seq 1 100) do touch $(($f-1)).tar.gz -t 200101010101 tar cvfz $f.tar.gz $(($f-1)).tar.gz done
I get different file sizes, from
Why does that happen, and what can I do to prevent it from happening?