There was a test when you commpression one file repeatly:
➜ ~ ls -al test
-rw-r--r--@ 1 liugang staff 3180 11 26 18:04 test
➜ ~ gzip test
➜ ~ ls -al test.gz
-rw-r--r--@ 1 liugang staff 842 11 26 18:04 test.gz
➜ ~ mv test.gz test
➜ ~ gzip test
➜ ~ ls -al test.gz
-rw-r--r--@ 1 liugang staff 870 11 26 18:04 test.gz
➜ ~ mv test.gz test
➜ ~ gzip test
➜ ~ ls -al test.gz
-rw-r--r--@ 1 liugang staff 898 11 26 18:04 test.gz
➜ ~ mv test.gz test
➜ ~ gzip test
➜ ~ ls -al test.gz
-rw-r--r--@ 1 liugang staff 926 11 26 18:04 test.gz
➜ ~ mv test.gz test
➜ ~ gzip test
➜ ~ ls -al test.gz
-rw-r--r--@ 1 liugang staff 948 11 26 18:04 test.gz
➜ ~ mv test.gz test
➜ ~ gzip test
➜ ~ ls -al test.gz
-rw-r--r--@ 1 liugang staff 976 11 26 18:04 test.gz
➜ ~ mv test.gz test
➜ ~ gzip -9 test
➜ ~ ls -al test.gz
-rw-r--r--@ 1 liugang staff 1004 11 26 18:04 test.gz
For the result below , we can find that , only the first compression can reduce the file size , Then compress the gziped file will increse the size of this file.
The gzip command we usually used :
#compress the file
gzip filename
#display the compressed file
gzcat filename.gz
#uncompress file
gzip -d filename
#eg: compress the file use the best compress alog , and stag the origin file
gzip -9 -c filename > filename.gz
The tar command we usually used :
#pack and compress
tar -zcvf file.tar.gz dirname
#uncompress
tar -zxvf file.tar.gz
#list the files in the gz file
tar -ztvf file.tar.gz
#only uncompress one file in the .gz file
tar -zxvf file.tar.gz gzdir/filename
#uncompre .gz file to specify dir
tar -zxvf file.tar.gz -C dirname