How to prevent `diff -rq` from showing newly created files, when comparing the different versions of a folder?

I am doing diff -rq to check the difference between 2 folders (A and B). I don’t want to know if folder A has any new files because that’s expected. How do I ensure that this information doesn’t come up?

Asked By: desert_ranger


Expanding on my comment now that I’m at an actual keyboard:

The only way to do what you want is to diff files individually. We can combine find and xargs to do that, something like this:

(cd B && find . -type f -print0) | xargs -0 -IPATH diff -q A/PATH B/PATH

This produces a list of all files in B relative to the top directory, and the uses xargs to run a series of diff -q commands comparing the file in B to the same path in A.

When the directories have identical content, it produces no output and the return code is 0:

$ (cd B && find . -type f -print0) | xargs -0 -IPATH diff -q A/PATH B/PATH
$ echo $?

When there are differences, diff -q prints a message to the console, and the return code is 123:

$ (cd B && find . -type f -print0) | xargs -0 -IPATH diff -q A/PATH B/PATH
Files A/./dir2/dir3/file1 and B/./dir2/dir3/file1 differ
$ echo $?
Answered By: larsks
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.