Diff Command – Compare Directories Ignoring Extensions

diff()filenames

I've got two directories with similar file names but different extensions. Here's an example:

DIR1:
 - IN89284.wav
 - OUT9920.wav

DIR2:
 - IN89284.mp3
 - OUT9920.mp3

I want to compare these directories but ignore the file extensions, so in that case they would be the same. How can I do that? I guess that I'd have to loop through the first directory, trim each file name (cut the extension) and then search for it in the second directory. Is there any better way to do that?

Best Answer

With zsh:

diff -u <(cd dir1 && printf '%s\n' **/*(D:r)) \
        <(cd dir2 && printf '%s\n' **/*(D:r))

(D) to include dot-files (hidden files), :r to get the root name (remove extension).

Using globbing guarantees a consistent sort order.

(that assumes file names don't have newline characters).

Related Question