Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I compare recursively 2 folders with same structure.
With using diff or git diff from bash command line?

share|improve this question

migrated from stackoverflow.com Sep 30 '12 at 20:31

This question came from our site for professional and enthusiast programmers.

4 Answers 4

up vote 2 down vote accepted

To compare 2 files, we use the diff command. How do we compare 2 directories? Specifically, we want to know what files/subdirectories are common, what are only in 1 directory but not the other use

diff dir1 dir2

if you are not interested in file differences use

diff -q dir1 dir2 |sort

diff orders its output alphabetically by file/subdirectory name. I prefer to group them by whether they are common, and whether they only exist in the first or second directory. That is why I piped the output of diff through sort in the above command.

Note that by default diff does not reach into the subdirectories to compare the files and subdirectories at that level. To change its behavior to recursively go down subdirectories, add -r.

diff -qr dir1 dir2 |sort

I hope this helps.

share|improve this answer

My favourite for a quick glance:

diff -Ewburq folder1/ folder2/

List filenames (ignoring all kinds of whitespace changes).

To see the whole diff in a nice viewer (removing the -q option)

diff -Ewbur folder1/ folder2/ | kompare -o -

You could probably find other (better?) diff tools (meld, k3diff etc.?)

If you want, you can include files 'new' to the set with -N

share|improve this answer
    
+1 I like this... But I love your avatar! –  Killercam Sep 28 '12 at 10:52
1  
@Killercam Cheers. Visit the Lounge<C++> one day if you like a party of animals :) –  sehe Sep 28 '12 at 10:56

Use the following command:

diff -r folder1 folder2
share|improve this answer
diff -Nur directory1 directory2
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.