Operating System - HP-UX
1819719 Members
2818 Online
109606 Solutions
New Discussion юеВ

Re: gzip compression ratio

 
William_34
New Member

gzip compression ratio

Hi, guys. This is my first post, so please be gentle. I'm trying to add a check into a script I'm writing to determine the size of a file after it has been gzip'd. This is basically just a log rotation script with a smart check to prevent it from filling up the directory I am archiving to. I'm running into problems finding information on the compression ratio. If anyone could point me in the right direction that would be great. Thanks in advance.
-William
8 REPLIES 8
John Palmer
Honored Contributor

Re: gzip compression ratio

Hi William,

Welcome to the forums!

gzip itself has a -l flag that tells you the compressed size, uncompressed size and ratio of a zipped file. E.g. gzip -l

Is this what you want?

Regards,
John
Fergus Hayne
Occasional Advisor

Re: gzip compression ratio

Hi, try using gzip -v this will tell you give you the percentage reduction.

You can capture this info and use it for your reporting.

example

RESULT=`gzip -v file 2>&1 | cut -d " " -f 2`
echo Compressed by $RESULT

Fergus
hmm
Helen French
Honored Contributor

Re: gzip compression ratio

Hi William:

Warm welcome to the best forums !

# man gzip

This man pages will give you all information you need. Also the -l option gives you the compression ratio.

HTH,
Shiju
Life is a promise, fulfill it!
Paul R. Dittrich
Esteemed Contributor

Re: gzip compression ratio

Hello William,

In general, most text files will compress by an average of roughly 50%, sometimes much more.
"Sparse" files can have a compression ratio over 95%.
Binary file data compression ratios are pretty unpredictable and will vary all over the range.
Files that are already compressed (mpegs, etc.) will not compress any further and may even increase in size if you attempt it.

HTH,
Paul
William_34
New Member

Re: gzip compression ratio

Thanks for replies. I tried to assign everyone the appropriate points, but keep getting "page not found" errors upon submit. Let me know if you didn't get your points. Ok. What I'm trying to do is get an approximation of the file I'm intending to gzip before I actually gzip. As far as I could tell from the man page for gzip, I didn't see it reference any kind of preview option. So, what I want to do is find out what ratio it reduces the file down to before I compress it. I've ran tests with several files of varying size, but have not been able to find a consistant ratio of compression. Is there a single consistant ratio of compression or is the ratio determined by the actual file size? Thanks in advance.
-William
MANOJ SRIVASTAVA
Honored Contributor

Re: gzip compression ratio

Hi William

There is no fixed thumb rul for the compression raio , actually all teh files ahve empty blanks and repetitive patterns which are remved and only the data is compacted . So if you have a file which has lots of blank spaces it will have a btter compression ratio. Man gzip is the way to go about it.


All the best.


Manoj Srivastava
John Palmer
Honored Contributor

Re: gzip compression ratio

The compression ratio achieved depends entirely on the data itself (see the man page).

You could 'preview' the gzip by running the following:
gzip -c | wc -c
This will display the compressed size without requiring any diskspace. gzip is CPU intensive though.

Regards,
John
William_34
New Member

Re: gzip compression ratio

John, thank you. You solved my problem. Thanks everyone for all of your responses. Again, let me know if you didn't get your points.
Thanks,
William