给定两个目录树,如何找出内容不同的文件? [英] Given two directory trees, how can I find out which files differ by content?

查看:57
本文介绍了给定两个目录树,如何找出内容不同的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想找到两个目录树之间的差异,通常只执行:

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

diff -r dir1/ dir2/

这将准确输出相应文件之间的区别.我感兴趣的只是获得内容不同的相应文件的列表.我以为这只是将命令行选项传递给diff的问题,但是我在手册页上找不到任何内容.

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.

有什么建议吗?

推荐答案

您说过Linux,所以运气不好(至少它应该可用,不确定何时添加):

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

diff --brief --recursive dir1/ dir2/ # GNU long options
diff -qr dir1/ dir2/ # common short options

应该做你所需要的.

如果您还想查看两个目录中可能不存在的文件的差异:

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

diff --brief --recursive --new-file dir1/ dir2/ # GNU long options
diff -qrN dir1/ dir2/ # common short options

这篇关于给定两个目录树,如何找出内容不同的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆