Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
425 views
in Technique[技术] by (71.8m points)

linux - 给定两个目录树,如何找出哪些文件有所不同?(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.

(我认为这只是将命令行选项传递给diff ,但我在手册页上找不到任何内容。)

Any suggestions?

(有什么建议?)

  ask by Mansoor Siddiqui translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

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

Should do what you need.

(应该做你需要的。)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...