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

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


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.


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.