gzip produces different output from the same input


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers gzip produces different output from the same input
# 1  
Old 06-29-2010
Question gzip produces different output from the same input

Hi there,

I'm puzzled. Compressing the same file (same name, same md5sum) at two different times will produce a different output. I mean the md5sum of the resulting .gz files are different.
Does it make any sens to any of you?
I'd like some explanations if you know what's going on.

Thanks
Santiago
# 2  
Old 06-29-2010
Yes. gzip saves the name of the original file,if possible, and timestamp. You can check it with the "file" command.
# 3  
Old 06-29-2010
Thanks pludi.
The thing is that I ran gzip for the exact same file twice:
Code:
santiago:~$ cp original copy
santiago:~$ gzip copy
santiago:~$ md5sum copy.gz
603343de9a6c295f00dc4759f6919031  copy.gz
santiago:~$ rm copy.gz
santiago:~$ cp original copy
santiago:~$ gzip copy
santiago:~$ md5sum copy.gz
e4da2538a243cb49cf6212a0a20a60ce  copy.gz

How can it be different?
# 4  
Old 06-29-2010
Because gzip saves, into the file, the modification time of the file, as well as the original file name if possible:
Code:
$ echo "TestTestTest" > test1.txt
$ stat test1.txt
  File: `test1.txt'
  Size: 13              Blocks: 8          IO Block: 4096   regular file
Device: 801h/2049d      Inode: 1872126     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    1000/   pludi)   Gid: (  100/   users)
Access: 2010-06-29 14:04:56.000000000 +0200
Modify: 2010-06-29 14:04:56.000000000 +0200
Change: 2010-06-29 14:04:56.000000000 +0200
$ gzip -9c test1.txt > test1_1.txt.gz
$ touch test1.txt
$ stat test1.txt
  File: `test1.txt'
  Size: 13              Blocks: 8          IO Block: 4096   regular file
Device: 801h/2049d      Inode: 1872126     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    1000/   pludi)   Gid: (  100/   users)
Access: 2010-06-29 14:05:14.000000000 +0200
Modify: 2010-06-29 14:05:14.000000000 +0200
Change: 2010-06-29 14:05:14.000000000 +0200
$ gzip -9c test1.txt > test1_2.txt.gz
$ md5sum test1_?.txt.gz
de2048a553d7f5fe9815f4d0f0c286e3  test1_1.txt.gz
02e66fb2b786c4585f012dff592010f3  test1_2.txt.gz
$ file test1_?.txt.gz
test1_1.txt.gz: gzip compressed data, was "test1.txt", from Unix, last modified: Tue Jun 29 14:04:56 2010, max compression
test1_2.txt.gz: gzip compressed data, was "test1.txt", from Unix, last modified: Tue Jun 29 14:05:14 2010, max compression

If it can't save the original files modification time (eg because it's being piped into gzip) it saves the creation time of the compressed file instead.
This User Gave Thanks to pludi For This Post:
# 5  
Old 06-29-2010
Thanks again pludi
My problem is that I thought that copying a file actually kept the modification time wich is wrong.
I ran the same test with option -p to cp command and the conclusion is obvious:
Code:
santiago:~$ rm -f copy*
santiago:~$ cp -p original copy
santiago:~$ gzip copy
santiago:~$ md5sum copy.gz
8dab7a05d099f445698b04f0d1e59873  copy.gz
santiago:~$ file copy.gz
copy.gz: gzip compressed data, was "copy", from Unix, last modified: Tue Jun 29 14:48:31 2010
santiago:~$
santiago:~$ rm -f copy*
santiago:~$ cp -p original copy
santiago:~$ gzip copy
santiago:~$ md5sum copy.gz
8dab7a05d099f445698b04f0d1e59873  copy.gz
santiago:~$ file copy.gz
copy.gz: gzip compressed data, was "copy", from Unix, last modified: Tue Jun 29 14:48:31 2010

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing the output of a gzip command intact

how can i get the printf command or the echo command to print the data that are inbetween the first and the last quotes? #!/bin/sh printf '%s\n' "^_<8b>^H^@U<8c>MX^@^Cí=ÙzÚH<97>×ð^Teìn<8c>Ób_<9d><9f>dXd<9b>^N^F7<82>8qâÎ'^K^Y^T<83>D<90>°M^Lý^Hó^Fs5w3ß|s5/ÐýbS%©<84>^DBH... (4 Replies)
Discussion started by: SkySmart
4 Replies

2. Shell Programming and Scripting

awk runs and produces output but with error

When I run the awk below, I get an error message awk -v OFS='\t' '$(NF-1)=="Benign" || ($(NF-2) OFS $(NF-1))=="Likely Benign" {$(NF)=$(NF-2) OFS $(NF-1)} {print $0 }' input awk: cmd. line:1: (FILENAME=VUS FNR=8) fatal: attempt to access field -1 input Chr Start End Ref ... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. AIX

Gzip status output is not redirecting.

Dear all I am facing issue in one part of my script. in this part i am trying to zip the files but want the status to be redirected to a text file YAMVASSRV02_vas> YAMVASSRV02_vas> cat final_col.sh gzip -cv /data01/oracle/oradata/vas/control/control01.ctl > ... (2 Replies)
Discussion started by: javeedkaleem
2 Replies

4. Shell Programming and Scripting

Need a shell script to compare two directories and produces the output

Hi, I am using solaris OS 10 and Bash shell.I need a script which will compare the two directories and produces the output. Step 1: In detail say suppoose I have machine one and have a directory dir1. Script should iterate through the directories and subdirectories inside and produce the output... (10 Replies)
Discussion started by: muraliinfy04
10 Replies

5. UNIX for Dummies Questions & Answers

linux sort command produces strange output

cat a .a ba .b bb .c bc sort a .a .b ba bb bc .c NOTE: .a and .b appears before ba and bb, where as .c appears after bc. In general (3 Replies)
Discussion started by: ajb
3 Replies

6. Shell Programming and Scripting

Redirect output to tar.gzip

I would like to make a listing of files in a large directory and output it to tar.gz. Is it possible to do this in one command? For example; I would like the text output from this command to be outputted to a directory.tar.gz file. ls -al -R /bigdir Is it possible to do it in memory... (5 Replies)
Discussion started by: lewk
5 Replies

7. UNIX for Advanced & Expert Users

gzip vs pipe gzip: produce different file size

Hi All, I have a random test file: test.txt, size: 146 $ ll test.txt $ 146 test.txt Take 1: $ cat test.txt | gzip > test.txt.gz $ ll test.txt.gz $ 124 test.txt.gz Take 2: $ gzip test.txt $ ll test.txt.gz $ 133 test.txt.gz As you can see, gzipping a file and piping into gzip... (1 Reply)
Discussion started by: hanfresco
1 Replies

8. Shell Programming and Scripting

Using piped input to gzip

Can anyone tell me why does'nt the following command work? find /gfp1/home/arijit -name "*.sas7bdat" | gzip I am trying to compress all files with extension sas7bdat with gzip. It gives error message gzip: compressed data not written to a terminal. Use -f to force compression.... (5 Replies)
Discussion started by: bs0409
5 Replies

9. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

10. Linux

vgscan produces no output using file descriptors on Oracle Enterprise Linux.

I wrote a simple program which will create a child process to execute a command and the output will be redirected to the file. Please have a look at the following code -> #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <fcntl.h> void execute(char **argv) { ... (0 Replies)
Discussion started by: sandiworld
0 Replies
Login or Register to Ask a Question