Home > front end >  How can I diff two directories in bash recursively for only 1 file name
How can I diff two directories in bash recursively for only 1 file name

Time:02-05

Currently I am trying this

diff -r /develop /us-prod

Which shows all the differences between the two. But all I really care about here is a file named schema.json, which is guaranteed to be there in all directories. But this file can be different. I want to diff these two directories, but only if the file name is schema.json.

I see that you can do -x to exclude files, but it is difficult to say which other files could be in there. There are some guaranteed files to be there, but some are not. Is there more an "inclusion" than an exclude?

CodePudding user response:

You can try this :

find /develop -type f -name schema.json -exec bash -c\
     'diff "$1" "/us-prod${1#/develop}"' _ {} \;

CodePudding user response:

Assuming the both directories have just one schema.json file for each directory including their subdirectories, would you please try:

diff $(find /develop -type f -name schema.json) $(find /us-prod -type f -name schema.json)
  •  Tags:  
  • Related