2

Let's say this is my file tree:

a
a/file1
a/subdir1
a/subdir1/file1
a/subdir1/file2
b
b/file1

When I run diff -qr a b, it returns the below. It is doing a recursive diff, but it doesn't list the files under the subdir.

Files a/file1 and b/file1 differ
Only in a: subdir1

What I would like to see is the below. Are there any diff options to do this?

Files a/file1 and b/file1 differ
Only in a: subdir1
Only in a: subdir1/file1
Only in a: subdir1/file2

(Note: I am using Ubuntu, GNU diffutils 3.2)

wisbucky
  • 33,218
  • 10
  • 150
  • 101

2 Answers2

0

see Given two directory trees, how can I find out which files differ?

It does not appear that diff provides a comparison or output regarding files that exist in one directory and not the other as you are trying to do. As Matt has pointed out below, you must parse the file lists below both a and b outside of diff and call diff to compare those files that exist in both directories and output the names of those that only appear in one directory. It would be nice if there was something like that in diff, but it is essentially asking diff to compare the differences between file_a and nonexistent_file_b. Sorry for the initial misreading.

Community
  • 1
  • 1
David C. Rankin
  • 81,885
  • 6
  • 58
  • 85
  • `--brief` is the same as `-q`, see the second answer in that question. Also that question doesn't answer this one, because @wisbucky wants to see all the files that differ and not just stop at subdirectories. – hmatt1 Jun 28 '14 at 04:02
0

The reason why you get that output when running diff -qr a b is because the subdir1 is only in a. Because of that, everything under a must be different than in b so it apparently doesn't go through and list all the files. I haven't found a way for it to list all the files regardless. I put together another command that will hopefully help!

My file structure:

Matt@MattPC ~/perl/testing/10
$ find .
.
./a
./a/file1
./a/subdir1
./a/subdir1/file1
./a/subdir1/file2
./b
./b/file1

The diff command you ran (same output):

Matt@MattPC ~/perl/testing/10
$ diff -q -r a b
Only in a: subdir1

Here's a command I wrote that will hopefully get you what you need. Basically, it calls find a and find b and pipes the output to diff to compare them. However, we have to pipe that to sed 's/^[^/]\+//' to remove the name of the first directory, in this case a and b.

Matt@MattPC ~/perl/testing/10
$ diff <(find a | sed 's/^[^/]\+//') <(find b | sed 's/^[^/]\+//')
3,5d2
< /subdir1
< /subdir1/file1
< /subdir1/file2

Hope this helps! Let me know if the command needs tweeking.

hmatt1
  • 4,939
  • 3
  • 30
  • 51