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

If I want find the differences between two directory trees, I usually just execute:

diff -r dir1/ dir2/

This outputs exactly what the differences are between corresponding files. I'm interested in just getting a list of corresponding files whose content differs. I assumed that this would simply be a matter of passing a command line option to diff , but I couldn't find anything on the man page.

Any suggestions?


You said Linux, so you luck out (at least it should be available, not sure when it was added):

diff --brief -r dir1/ dir2/

Should do what you need.

If you also want to see differences for files that may not exist in either directory:

diff --brief -Nr dir1/ dir2/

The command I use is:

diff -qr dir1/ dir2/

It is exactly the same as Mark's :) But his answer bothered me as it uses different types of flags, and it made me look twice. Using Mark's more verbose flags it would be:

diff  --brief --recursive dir1/ dir2/

I apologise for posting when the other answer is perfectly acceptable. Could not stop myself... working on being less pedantic.


我喜欢使用git diff --no-index dir1/ dir2/ ,因为它可以显示颜色的差异(如果您在git配置中设置了该选项),并且它显示使用长分页输出时的所有差异“减”。

链接地址: http://www.djcxy.com/p/13718.html

上一篇: exec使用多个命令

下一篇: 给定两个目录树,我怎样才能找出哪些文件不同?