The behavior you experienced is by design. I don't think you can get what you want, unless you allow tools other than diff
. From your comment:
When I read "recursively" I assume that the process won't stop at the first level.
It doesn't stop because of the first level. Mind what recursion means:
using functions that call themselves from within their own code
(source: here; emphasis mine)
Imagine you have a common subdirectory foo
in both diff1
and diff2
. Recursion means that your original command diff -r diff1 diff2
at some point calls
diff -r diff1/foo diff2/foo
OK, in practice this is most likely done by a subroutine calling itself within a single process (but I guess an implementation that actually calls diff
executable is possible). Still logically it's like this.
You have diff1/folder
but there's no diff2/folder
. How can you call diff
to compare these? In other words, what should <unknown_name>
be, so you get your desired output from the below form?
diff -r diff1/folder diff2/<unknown_name>
There is no <unknown_name>
that fits. Recursive diff
cannot descend to folder
without turning into something like recursive ls
or find
. Being recursive ls
or find
is not its job.
Still you can query diff1/folder
with ls -R
or find
(recursive by default), after you learn from diff
that Only in diff1: folder
.