This has been partly covered by Comparing the contents of two directories but I have a slightly twist on this problem.

I have directories Dir1 and Dir2. Their subdirectory structures should be the same, which is something I want to check. But I also want to check the files within them. They should have the same file names but every file within Dir1 has extension .type1 and every file in Dir2 has .type2. When I use the solution linked above Dir1/bob/file.type1 and Dir2/bob/file.type2 are viewed as different.

How do I make the above linked solution blind to extensions?

  • What should the output look like? Sep 6 '16 at 10:31

Something like

diff <(cd Dir1 && find . | sort | sed 's/\.type1$//') <(cd Dir2 && find . | sort | sed 's/\.type2$//')

could be a solution.

The command will hide .type1 and .type2 extensions in both directories so they won't impact the diff.

Here's a simple example:

user@hostname:/tmp/test-diff$ find Dir* | sort

The diff command will highlight that file1 is in Dir1 (<), but not in Dir2 and file2 and file4 are in Dir2 (>), but not in Dir1

user@hostname:/tmp/test-diff$ diff <(cd Dir1 && find . | sort | sed 's/\.type1$//') <(cd Dir2 && find . | sort | sed 's/\.type2$//')
< ./file1
> ./file2
> ./file4
  • Thanks, it seems to go towards an answer. (cd Dir1 && find . | sort | sed 's/\.type1$//') and (cd Dir2 && find . | sort | sed 's/\.type2$//') each return a "bleached" directory and file listing but the diff outputs directories they both have and some lines like "7c9,16" and "2a3,4" . If I had to guess it's not allowing "missing files" to be skipped over, ie if Dir2 is missing file 3 of 10 then the last 7 files will not line up with the file names from Dir1. Sep 6 '16 at 10:04
  • @AlphaNumeric I think I don't fully get the problem. I added an example in the answer. If you want only the file names (with the "directory indicator") you can just | grep '^[<>]'
    – MaxChinni
    Sep 6 '16 at 10:31
  • Hi Max. The expanded edit you made cleared things up a lot and I understand what the output was giving now. I'll "accept" your answer now. Thanks for your help. Sep 7 '16 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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