Compression ratios of .tbz file | Unix Linux Forums | Red Hat

  Go Back    


Red Hat Red Hat is the world's leading open source technology solutions provider with offerings including Red Hat Enterprise Linux (RHEL), Fedora, open source applications, security and systems management, virtualization, and Services Oriented Architecture (SOA) solutions.

Compression ratios of .tbz file

Red Hat


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-13-2011
maverick_here maverick_here is offline
Registered User
 
Join Date: May 2009
Last Activity: 30 October 2014, 10:43 PM EDT
Location: Hyderabad
Posts: 132
Thanks: 0
Thanked 5 Times in 4 Posts
Compression ratios of .tbz file

Hi,

I have a question about finding the compression ratios of a zip (bzip2) file.I have written a procedure which upon certain criteria tar's and bzip2 certain directories and moves them to a near line storage.

Yesterday I happened to stumble upon it. The procedure has tared and bzipped 6 GB of data to 800MB. Is there any attribute in tar command which would yield a summary of the compression.Though I have gone through the man page of tar, I have not found anything affirmative.

Thanks in advance
Syed
Sponsored Links
    #2  
Old 09-13-2011
pludi's Avatar
pludi pludi is offline Forum Advisor  
Cat herder
 
Join Date: Dec 2008
Last Activity: 28 March 2014, 8:35 AM EDT
Location: Vienna, Austria, Earth
Posts: 5,522
Thanks: 38
Thanked 335 Times in 308 Posts
In short: no.
tar doesn't compress anything, it's just an archiver, meaning it combines a list of files (including meta information like access times, permissions, ...) into one larger file. As a bonus it supports passing this file stream through a compression utility like gzip or bzip2. These 2 commands are completely equal, and the resulting files usually even have the same checksum:
Code:
# tar -cf - directory | bzip2 -c > archive.tbz
# tar -cjf archive.tbz directory

One way to get the ratio would be by getting the sizes of the original and the compressed file with du, and feeding it to bc:
Code:
orig=$( du -k directory )
comp=$( du -k archive.tbz )
ratio=$( echo "scale=5; $comp/$orig*100" | bc )

Sponsored Links
    #3  
Old 09-13-2011
maverick_here maverick_here is offline
Registered User
 
Join Date: May 2009
Last Activity: 30 October 2014, 10:43 PM EDT
Location: Hyderabad
Posts: 132
Thanks: 0
Thanked 5 Times in 4 Posts
Ok, is there anyway of doing it while we actually create the tbz file via tar command,the command I,m using is as follows


Code:
tar cjfPpT /path/to/file.tbz  /path/to/inputlist

    #4  
Old 09-13-2011
pludi's Avatar
pludi pludi is offline Forum Advisor  
Cat herder
 
Join Date: Dec 2008
Last Activity: 28 March 2014, 8:35 AM EDT
Location: Vienna, Austria, Earth
Posts: 5,522
Thanks: 38
Thanked 335 Times in 308 Posts
No. Instead of du you could try capture the output of the --totals option, but that's about it.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
file compression Demerzel Shell Programming and Scripting 1 08-31-2010 09:07 PM
.z file compression Gonecat UNIX for Dummies Questions & Answers 3 11-30-2006 11:33 AM
Finding Compression Ratios nortypig Shell Programming and Scripting 3 08-22-2006 11:59 PM
file compression kristy UNIX for Dummies Questions & Answers 2 05-16-2001 11:57 AM



All times are GMT -4. The time now is 12:27 PM.