Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

We have two zip files and would like to compare them.

We're also interested in calculating the percentage difference between them and the file size. Is there a tool that can do this quickly?

share|improve this question
1  
"percentage difference" is an ambiguous metric. If the original file is 100 bytes long, and is modified by inserting a new byte in the exact middle, is the new file "different" by 1% or 50%? Do you have a different answer if it were text files and it's lines instead of bytes? I.E. compare the results of cmp versus diff. –  sawdust Mar 24 '13 at 23:09
    
I guess the OP refers to the difference in file size (probably to compare compression rate?) –  Pincopallino Mar 25 '13 at 16:11

1 Answer 1

You could try a bash script like this one:

#!/bin/bash
SIZE1=$(stat -f "%z" "$1")
SIZE2=$(stat -f "%z" "$2")
PERC=$(bc <<< "scale=2; ($SIZE2 - $SIZE1)/$SIZE1 * 100")
echo "$PERC %"

You then call the script by passing the two files as arguments. I used the command stat -f "%z" "$1" to get the file size and it works on OS X. Depending on your Linux distribution, you might need a different syntax, such as stat -c%s FILENAME, or du -b FILENAME. Try in your console, you should get the number of bytes as output.

Notice that we need to call the program bc because Bash can't do floating point arithmetics.

Of course you can modify the script to fulfill your needs. If you need to compare two compressed files with the uncompressed file you can add another variable and do the desired maths using bc.

share|improve this answer
    
Thanks, Pincopallino. I am trying out with your suggestions. –  chz Apr 6 '13 at 4:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.