given two directory trees how to find which files are the same?

醉酒当歌 提交于 2019-12-20 08:47:36

问题


I am writing a bash script, and I would like to know which files are the same in two directory trees.

It would be the opposite of using diff.

Well i found the answer myself. I had tried it before, but I thought it did not work.

diff -srq dir1/ dir2/ | grep identical

回答1:


Well i found the answer myself. I had tried it before, but I thought it did not work.

diff -srq dir1/ dir2/ | grep identical

What -srq means? From diff --help :

-s  --report-identical-files  Report when two files are the same.
-r  --recursive  Recursively compare any subdirectories found.
-q  --brief  Output only whether files differ.



回答2:


You can use a utility like fdupes or rdfind to list duplicate files. For example:

fdupes --recurse dir1 dir2

You might also want to use the --sameline flag to list all duplicates on the same line, rather than in text blocks, depending on how you want to parse the results.



来源:https://stackoverflow.com/questions/10087571/given-two-directory-trees-how-to-find-which-files-are-the-same

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!