2

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

5 Answers 5

7

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.

3

Simply you can do:

git diff --no-index FOLDER1 FOLDER2
1

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

2
  • +1 I like this... But I love your avatar!
    – MoonKnight
    Sep 28, 2012 at 10:52
  • 1
    @Killercam Cheers. Visit the Lounge<C++> one day if you like a party of animals :)
    – sehe
    Sep 28, 2012 at 10:56
1
diff -Nur directory1 directory2
0

Use the following command:

diff -r folder1 folder2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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