对于相同的tar内容,不同的md5sums

我运行一个testing,从同一目录创build两个焦点(其文件保持不变),我发现他们的md5sum是不同的。 我认为有一些时间戳被包含在焦油的头,但我还没有find重写它的方式。 我的操作系统是Ubuntu 9.1。 有任何想法吗 ?

谢谢。

正如丹尼斯指出的那样,这是gzip。 部分gzip头文件是压缩文件中的任何一个mod时间。 如果你需要gzip,你可以压缩tar文件作为tar之外的额外步骤,而不是使用tar的内部gzip。 gzip命令有一个标志来禁止保存修改时间。

 tar -c ./bin |gzip -n >one.tgz tar -c ./bin |gzip -n >two.tgz md5sum one.tgz two.tgz 

这不会影响tarfile内部的时间,只会影响gzip头文件中的时间。

我也有这个问题,为了使gzip不改变时间戳,使用gzip -n

-n,–no-name不保存或恢复原始名称和时间戳

 [valter.silva@alog ~]$ gzip --help Usage: gzip [OPTION]... [FILE]... Compress or uncompress FILEs (by default, compress FILES in-place). Mandatory arguments to long options are mandatory for short options too. -c, --stdout write on standard output, keep original files unchanged -d, --decompress decompress -f, --force force overwrite of output file and compress links -h, --help give this help -l, --list list compressed file contents -L, --license display software license -n, --no-name do not save or restore the original name and time stamp -N, --name save or restore the original name and time stamp -q, --quiet suppress all warnings -r, --recursive operate recursively on directories -S, --suffix=SUF use suffix SUF on compressed files -t, --test test compressed file integrity -v, --verbose verbose mode -V, --version display version number -1, --fast compress faster -9, --best compress better --rsyncable Make rsync-friendly archive With no FILE, or when FILE is -, read standard input. Report bugs to <[email protected]>. 

例:

 [valter.silva@alog ~]$ ls renewClaroMMSCanaisSemanal.log.gz s3 [valter.silva@alog ~]$ gunzip renew.log.gz [valter.silva@alog ~]$ gunzip s3/renew.log.gz [valter.silva@alog ~]$ md5sum renew.log d41d8cd98f00b204e9800998ecf8427e renew.log [valter.silva@alog ~]$ md5sum s3/renew.log d41d8cd98f00b204e9800998ecf8427e s3/renew.log [valter.silva@alog ~]$ gzip -n renew.log [valter.silva@alog ~]$ gzip -n s3/renew.log [valter.silva@alog ~]$ md5sum renew.log.gz 7029066c27ac6f5ef18d660d5741979a renew.log.gz [valter.silva@alog ~]$ md5sum s3/renew.log.gz 7029066c27ac6f5ef18d660d5741979a s3/renew.log.gz 

要制作一个一致的校验和的tar文件,只需在GZIP=-n前面加上:

 GZIP=-n tar -zcf myOutputTarball.tar /home/luke/directoryIWantToZip 

这是如何工作的: Tar可以接受使用临时GZIP环境variables的gzip选项,如上所述。 就像Valter所说的那样,tar使用gzip,默认情况下会在归档中添加一个时间戳。 这意味着当你压缩相同的文件时你会得到不同的校验和。 -n选项禁用该时间戳。