Identical is pretty easy. Maybe something like this.<p><pre><code>    #!&#x2F;bin&#x2F;sh
    here=$PWD
    dir=.
    depth=
    rm -f &#x2F;tmp&#x2F;list
    
    [ $# -eq 1 ] &amp;&amp;
      [ -e &quot;$1&quot; ] &amp;&amp; dir=$1 || depth=$1 
    
    [ $# -eq 2 ] &amp;&amp; for i in &quot;$@&quot;; do
      [ -e &quot;$i&quot; ] &amp;&amp; dir=$i || depth=$i
    done
    
    for each in $(find -L $dir -type d -depth $depth 2&gt;&#x2F;dev&#x2F;null); do
      [ -x &quot;$each&quot; ] &amp;&amp; cd &quot;$each&quot; &amp;&amp;
      sha=$(tar c . 2&gt;&#x2F;dev&#x2F;null | tar xmvO 2&gt;&amp;1 | xz | shasum | sed &#x27;s| .*||&#x27;) 
      [ $(find . 2&gt;&#x2F;dev&#x2F;null | wc -l) -gt 1 ] &amp;&amp; echo $sha $each &gt;&gt; &#x2F;tmp&#x2F;list
      cd &quot;$here&quot;
    done
    
    for sha in $(cat &#x2F;tmp&#x2F;list | sed &#x27;s| .*||&#x27; | sort | uniq); do
      [ $(grep $sha &#x2F;tmp&#x2F;list | wc -l) -gt 1 ]  &amp;&amp;
        echo Identical directories: &amp;&amp; grep $sha &#x2F;tmp&#x2F;list | sed &#x27;s|.* ||&#x27; &amp;&amp; echo
    done
</code></pre>
Similar and &quot;similar-and-strictly-newer&quot; both are much trickier as you have to invent a rubric for what &quot;similar&quot; mean, and `diff -qr` isn&#x27;t going to tell you if, say, the files are mostly the same, but have been moved into a subdirector. So I&#x27;d probably use git, traversing the file tree by moving the .git dir around and adding each candidate directory as a different branch, and doing a `git gc` each time to try to keep the size of the index manageable. Then doing a `git diff [--word-diff] [--stat] --find-copies-harder` between branches will pick up files that have been moved around, etc. You could literally do this for every directory and subdirectory, but if you can narrow it down to, say, directories with the same baseman, it would be substantially easier.<p>On the other hand, I would say I suffer from this same ailment, I just mostly don&#x27;t bother sorting it out. I just use something like <a href="http:&#x2F;&#x2F;cpansearch.perl.org&#x2F;src&#x2F;ANDK&#x2F;Perl-Repository-APC-2.002001&#x2F;eg&#x2F;trimtrees.pl" rel="nofollow">http:&#x2F;&#x2F;cpansearch.perl.org&#x2F;src&#x2F;ANDK&#x2F;Perl-Repository-APC-2.00...</a> to make hard links between identical files, keeping the size of the monstrosity in check.