Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try:</p> <pre><code>ls -1 | tr '[A-Z]' '[a-z]' | sort | uniq -c | grep -v " 1 " </code></pre> <p>Simple, really :-) Aren't pipelines wonderful beasts?</p> <p>The <code>ls -1</code> gives you the files one per line, the <code>tr '[A-Z]' '[a-z]'</code> converts all uppercase to lowercase, the <code>sort</code> sorts them (surprisingly enough), <code>uniq -c</code> removes subsequent occurrences of duplicate lines whilst giving you a count as well and, finally, the <code>grep -v " 1 "</code> strips out those lines where the count was one.</p> <p>When I run this in a directory with one "duplicate" (I copied <code>qq</code> to <code>qQ</code>), I get:</p> <pre><code>2 qq </code></pre> <p>For the "this directory and every subdirectory" version, just replace <code>ls -1</code> with <code>find .</code> or <code>find DIRNAME</code> if you want a specific directory starting point (<code>DIRNAME</code> is the directory name you want to use).</p> <p>This returns (for me):</p> <pre><code>2 ./.gconf/system/gstreamer/0.10/audio/profiles/mp3 2 ./.gconf/system/gstreamer/0.10/audio/profiles/mp3/%gconf.xml 2 ./.gnome2/accels/blackjack 2 ./qq </code></pre> <p>which are caused by:</p> <pre><code>pax&gt; ls -1d .gnome2/accels/[bB]* .gconf/system/gstreamer/0.10/audio/profiles/[mM]* [qQ]? .gconf/system/gstreamer/0.10/audio/profiles/mp3 .gconf/system/gstreamer/0.10/audio/profiles/MP3 .gnome2/accels/blackjack .gnome2/accels/Blackjack qq qQ </code></pre> <hr> <p><em>Update:</em></p> <p>Actually, on further reflection, the <code>tr</code> will lowercase <em>all</em> components of the path so that both of</p> <pre><code>/a/b/c /a/B/c </code></pre> <p>will be considered duplicates <em>even though they're in different directories</em>.</p> <p>If you only want duplicates within a single directory to show as a match, you can use the (rather monstrous):</p> <pre><code>perl -ne ' chomp; @flds = split (/\//); $lstf = $f[-1]; $lstf =~ tr/A-Z/a-z/; for ($i =0; $i ne $#flds; $i++) { print "$f[$i]/"; }; print "$x\n";' </code></pre> <p>in place of:</p> <pre><code>tr '[A-Z]' '[a-z]' </code></pre> <p>What it does is to only lowercase the final portion of the pathname rather than the whole thing. In addition, if you only want regular files (no directories, FIFOs and so forth), use <code>find -type f</code> to restrict what's returned.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload