Get original file size of zipped file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get original file size of zipped file
# 1  
Old 01-24-2012
Get original file size of zipped file

Hi,

I have a process which creates files and gzip all the files.
Next day, i need to get the file sizes ( before zip size ) of all the gzipped files. Is there any way i can get the original file sizes of gzipped files.
Gunzipping the files, getting the file size and gzipping again is not the approach i am looking for?
I appreciate your responses.

Thanks in Advance.
# 2  
Old 01-24-2012
17 seconds of grubbing around in man gunzip found gunzip -l

This even appears to work with streams, much to my surprise.
# 3  
Old 01-24-2012
If you use the -l switch, it lists the files and both their compressed and uncompressed sizes:

Code:
gzip -l file.txt.gz 
compressed        uncompressed  ratio uncompressed_name
      81                      68          20.6%      file.txt

Hope this helps.

---------- Post updated at 10:03 AM ---------- Previous update was at 10:02 AM ----------

17 seconds, damn, took me 20... coffee hasn't kicked in yet.
# 4  
Old 01-24-2012
Are you sure, Jim?

Code:
$ cat vectortop.png | gzip > vectortop.png.gz
$ gunzip -l vectortop.png.gz
         compressed        uncompressed  ratio uncompressed_name
               4360                4337  -0.1% vectortop.png
$

The 'cat' is to make sure it's not doing anything sneaky like running fstat on /dev/stdin.

---------- Post updated at 09:46 AM ---------- Previous update was at 09:14 AM ----------

yet again, working on streams:

Code:
$ gunzip -l < vectortop.png.gz
         compressed        uncompressed  ratio uncompressed_name
               4360                4337  -0.1% stdout

The limit seems to be that the compressed file has to be a file, not a stream, for the final size to be known. Maybe it has to seek to the end, impossible in a stream.

Code:
$ cat vectortop.png.gz | gunzip -l 
         compressed        uncompressed  ratio uncompressed_name
                 -1                  -1   0.0% stdout
$

# 5  
Old 01-24-2012
Thanks All.

Solutions worked
# 6  
Old 01-24-2012
Solution worked. Its displays the size in bytes.
How can i convert these sizes into MB?
# 7  
Old 01-24-2012
Divide by one million.

Code:
gunzip -l whatever.gz | awk 'NR==2 { print sprintf("%.1f MB", $2/(1000*1000)); exit }'

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find the original file size of encrypted file

Hi, I am trying to find out the original file size of an encrypted file in SunOS. The file was decrypted with gpg command. I want to know the size of the orginal file without decrypting it. I am using the below command, but it is not working for big files(more than 1 GB). gpg --passphrase... (4 Replies)
Discussion started by: vsachan
4 Replies

2. UNIX for Dummies Questions & Answers

How to know the Original size of the file without unzipping the File?

Hi, I don't have enough space on my Unix Box. So, I can't unzip the file and check the size of the file. So, I need to know, Is there any command, to check, how much the unzipped file takes after unzipping. Thanks in Advance. (4 Replies)
Discussion started by: Siva Sankar
4 Replies

3. UNIX for Dummies Questions & Answers

CSV file:Find duplicates, save original and duplicate records in a new file

Hi Unix gurus, Maybe it is too much to ask for but please take a moment and help me out. A very humble request to you gurus. I'm new to Unix and I have started learning Unix. I have this project which is way to advanced for me. File format: CSV file File has four columns with no header... (8 Replies)
Discussion started by: arvindosu
8 Replies

4. Solaris

How can I tell if a file is zipped or not?

SunOS xxxxxx 5.10 Generic_142900-15 sun4v sparc SUNW,T5240 We receive files that are sometimes zipped, but the file may not have the .gz or other extention that would indicated that the file is zipped. Is there a unix "test" command that I could use or something similar? Thanks in advance (7 Replies)
Discussion started by: Harleyrci
7 Replies

5. Shell Programming and Scripting

The scripts not able to make the file to size 0, every times it go back to its original size

#!/bin/sh ########################################################################################################## #This script is being used for AOK application for cleaning up the .out files and zip it under logs directory. # IBM # Created #For pdocap201/pdoca202 .out files for AOK #1.... (0 Replies)
Discussion started by: mridul10_crj
0 Replies

6. UNIX for Dummies Questions & Answers

reading a zipped file without unzipping it?

Dear all, I would like to ask how i can read a zipped file (file.gz) without actually unzipping it? i think there is a way to do so but i can't remember it.. can anyone help? thanks in advance.. (1 Reply)
Discussion started by: marwan
1 Replies

7. UNIX for Dummies Questions & Answers

how to check if file is zipped

I have a script that grabs files from directory , zips and moves them somewhere else. It works fine except the case when files it grabs are already zipped. Then it trys to zip it again which does not make sence. How can I check before zipping if file is already zipped? thanks in advance (3 Replies)
Discussion started by: arushunter
3 Replies

8. Shell Programming and Scripting

How to search a pattern inside a zipped file ie (.gz file) with out unzipping it

How to search a pattern inside a zipped file ie (.gz file) with out unzipping it? using grep command.. Bit urgent.. pls..help me (2 Replies)
Discussion started by: senraj01
2 Replies

9. UNIX for Dummies Questions & Answers

zipped or unzipped file

Is there a way you can tell if a file is still zipped or it's unzipped I have a file called ssss.zip and I would like to know if this file is still zipped or if it's unzipped? I'm on IBM AIX/RS6000 (3 Replies)
Discussion started by: ted
3 Replies
Login or Register to Ask a Question