Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Given two directory trees, how can I find out which files differ by content? [closed]

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?

like image 203
Mansoor Siddiqui Avatar asked Feb 14 '11 21:02

Mansoor Siddiqui


People also ask

How do I compare two directories in differences?

Click on the “Select Files or Folders” tab in the far left, to start a new comparison. Each comparison you run opens in a new tab. To start a new comparison, click on the “Select Files or Folders” tab in the far left, change the targets and click “Compare” again.

How do I compare the contents of two directories in Linux?

Now if you want to compare two directories instead then you have to use -q option and use directory path instead of file paths. Here is an example. The output will be shown as below. The above command will only compare the files in directory, but will not compare the contents of their subdirectories.


2 Answers

Try:

diff --brief --recursive dir1/ dir2/ 

Or alternatively, with the short flags -qr:

diff -qr dir1/ dir2/ 

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

diff --brief --recursive --new-file dir1/ dir2/  # with long options diff -qrN dir1/ dir2/                            # with short flag aliases 
like image 131
Mark Loeser Avatar answered Oct 11 '22 02:10

Mark Loeser


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.

like image 35
FPC Avatar answered Oct 11 '22 02:10

FPC