Check if archives are identical
<p>I'm using a shell script to automatically create a zipped backup of various directories every hour. If I haven't been working on any of them for quite some time, this creates alot of duplicate archives. MD5 hashes of the files don't match, because they do have different filenames &amp; creation dates etc.</p>

<p>Other than making sure there won't be duplicates in the first place, another option is checking if filesizes match, but that doesn't necesseraly mean they are duplicates.</p>

<p>Filenames are done like so;</p>

<pre><code>Qt_2012-03-15_23_00.tgz
Qt_2012-03-16_00_00.tgz
</code></pre>

<p>So maybe it would be an option to check if files have identical filesizes <strong>consequently</strong> (if that's the right word for it.)</p>

<p><strong>Pseudo code:</strong></p>

<pre><code>int previoussize = 0;
String previouspath = null;
String Filename = null;
String workDir = "/path/to/workDir ";
String processedDir = "/path/to/processedDir ";

//Loop over all files
for file in workDir
{
    //Match
    if(file.size() == previoussize)
    {
        if(previouspath!=null) //skip first loop
        {
            rm previouspath; //Delete file
        }
    }
    else //No Match
    {
      /*If there's no match, we can move the previous file 
        to another directory so it doesn't get checked again*/
        if(previouspath!=null) //skip first loop
        {
            mv previouspath processedDir/Filename;
        }
    }
    previoussize = file.size();
    previouspath = file.path();
    Filename = file.name();
}
</code></pre>

<p>Example:</p>

<pre><code>Qt_2012-03-15_23_00.tgz 10KB
Qt_2012-03-16_00_00.tgz 10KB
Qt_2012-03-16_01_00.tgz 10KB
Qt_2012-03-16_02_00.tgz 15KB
Qt_2012-03-16_03_00.tgz 10KB
Qt_2012-03-16_04_00.tgz 10KB
</code></pre>

<p>If I'm correct this would only delete the first 2 and the second to last one. The third and the fourth should be moved to the processedDir.</p>

<p>So I guess I have 2 questions:</p>

<ol>
<li><p>Would my pseudo code work the way I intend it to? (I find these things rather confusing.)</p></li>
<li><p>Is there a better/simpler/faster way? Because even though the chance of accidentally deleting non-identicals like that is very small, it's still a chance.</p></li>
</ol>
