How do you diff a directory for only files of a specific type?

Viewed 113315

I have a question about the diff command if I want a recursive directory diff but only for a specific file type, how to do that?

I tried using the exclude option but can only use one pattern only:

$ diff /destination/dir/1 /destination/dir/2 -r -x *.xml

with the command I can only exclude xml file type, even though there are files in the folder image type (png, gif, jpg), txt, php, etc

how to diff only certain file types.

9 Answers

I used the following command to find the diff of all *.tmpl files between DIR1 and DIR2. In my case this didn't yield any false positives, but it may for you, depending on the contents of your DIRS.

diff --brief DIR1 DIR2 | grep tmpl

Whilst it does not avoid the actual diff of other files, if your goal is to produce a patch file, or similar then you can use filterdiff from the patchutils package, e.g. to patch only your .py changes:

diff -ruNp /path/1 /path/2 | filterdiff -i "*.py" | tee /path/to/file.patch
Related