0

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?

2
  • I guess instead of using diff -rq you could perform a find . -type f ... in B, and then compare those files against the same files in A. Commented Mar 15, 2024 at 19:56
  • 1
    I thought that "new files" are related somehow to date (files that were created after certain time). If you just want to ignore files from A that aren't in B (as the accepted answer does), why not just run grep -v "Only in A:" on your diff -rq A B command? Commented Mar 17, 2024 at 9:07

1 Answer 1

2

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 $?
0

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 $?
123

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.