144

I am looking for a tool that is able to compare directories, not only files. Also it is important to be able to call the tool from the command line.

It would be great to have a free tool, but feel free to suggest commercial tools that fit the need.

16 Answers 16

19

For all the googlers... check out Beyond Compare it rules. Costs 30$ or 50$ for Pro version.

3
  • 6
    I usually try to avoid recommending commercial solution when free and open source alternatives exists but BeyondCompare is a special case where it does worth every penny... and is also multi platform. I have been using it for more 10 years and waited to long to get the MacOS version.
    – sorin
    Feb 15, 2017 at 10:14
  • 6
    It is now April 2020 and the pro version now costs $60. Apr 27, 2020 at 2:53
  • 2
    I've tried all the solutions on this page and I think Beyond Compare is 100% the best and most worthy recommendation. Aug 1, 2020 at 21:58
138

FileMerge (free), shipped with Xcode, offers a directory view.
A command line version is available through the Terminal application opendiff.

Here's how you can compare two directories with FileMerge:

  1. ⌘+space, type in "FileMerge" and open it.
  2. Click the "left" button and choose the folder you would like to move items FROM. (The "old" folder)
  3. Click the "right" button and choose the folder you would like to move items TO. ("new" folder) and click "Compare" button
  4. In the right panel, choose to exclude: "identical" and "Changed right". This way you will only see files which are missing in the "new" folder and ignore files your may have added in the "new" folder.
  5. Move files manually in Finder or let FileMerge do it, by choosing an option in the "Merge" dropdown in the right panel.
5
  • 2
    I would like to choose this answer because opendiff could be considered almost "bundled" with the OS X but when I tries to diff two folders it opened an ugly view that was not so easy to understand and also I was not able to see how do I merge two files in file view. I'm sure it is possible but if this basic feature is not obvious, I will prefer to look for something better ;)
    – sorin
    Mar 16, 2011 at 17:22
  • 1
    FileMerge is not as good as BeyondCompare, by a long shot. But it is free, and for a one-time requirement that's the price I was looking for :) Feb 13, 2021 at 13:32
  • FileMerge is giving me wrong results, telling me that files are modified or even added but when I check they weren't/exist both left and right. I suspect this may be related to the fact that the files on one side are located on Onedrive (but locally synched). In any case, I'll have to try something else.
    – Christoph
    Nov 9, 2021 at 8:29
  • Easy and fast if you already have Xcode installed! Dec 22, 2021 at 14:40
  • FileMerge is a good tool, but it takes time to learn how it works.
    – mdikici
    Jul 1, 2022 at 14:45
116

Built-in utility for macOS and Linux

If you don't mind using the terminal, the diff command can compare directories.
This utility is also available in most Linux distributions.

diff -rq directory1/ directory2/

-r indicates recurse through subdirectories, and -q gives brief output (i.e. don't show the actual diffs, just note what files/dirs are different).

Other useful options are:
-s report identical files,
-i ignore case in file contents,
--ignore-file-name-case ignore case when comparing file names.

If you want to avoid warnings (mostly usefulness warnings) about differences in the .DS_Store files, then use:

diff -rq directory1/ directory2/ | grep -v .DS_Store
3
  • 2
    You can exclude subfolders directly by diff --exclude node_modules
    – akauppi
    Jan 29, 2020 at 8:34
  • 2
    Even better, you can use diff -x node_modules Sep 11, 2020 at 1:45
  • 1
    I am trying to compare two Xcode projects. I started with "diff -rq" but the output was verbose to wade through as most differences were nested down several levels, resulting in excessively long lines just to report that they differ. I tried pasting that output into a spreadsheet to dissect the lines and that inspired me to go looking for a visual comparison tool like many of the others mentioned here. I'm currently exploring Meld, DirEqual, and FreeFileSync and realizing that the display format makes a big difference in readability and clarity. This thread has many others for me to try.
    – August
    Aug 31, 2023 at 20:07
25

Diffmerge should meet all your requirements.

6
  • I just hope that they will make an installer that will be able to install the command line starters and improve the current install experience.
    – sorin
    Mar 16, 2011 at 17:24
  • 4
    This is an old topic - but I installed it via brew cask install diffmerge and it installed without problems.
    – Rainer
    Oct 16, 2015 at 7:17
  • 1
    Apr 2016: It is still maintained, and still one of my go-to development tools.
    – JRobert
    Apr 14, 2016 at 13:16
  • FWIW I tried brew cask install diffmerge today (June 2020) and when I tried to run diffmerge I got an alert box telling me that MacOS wasn't going to run the program because it can't verify the developer. (diffmerge did not run) Jun 30, 2020 at 4:17
  • 3
    @MikeTheTall Isn't that usual for apps not from app store ? Did you tried directly Ctrl-click the app icon and then choose open from the shortcut menu ?
    – Anoop D
    Aug 20, 2020 at 17:15
17

Another neat tool to achieve this is rsync, as described on Unix & Linux StackExchange. To compare two folders you can do:

rsync -avun $SOURCE $TARGET

And if you are concerned about corrupt files / bit rot there is also the -c option to compare file checksums. This takes much more time of course as all files are checked in detail.

rsync -avnc $SOURCE $TARGET
1
  • Great reference for its usefulness on all Unixes 🙏🏻.
    – dan
    Jan 2, 2019 at 13:23
15

You should try the powerful open-source software meld. The Mac version can be found at Meld for OSX. It supports both directory and file comparison and works great under Mac.

I was told to improve this answer and explain why meld is good. Generally speaking, Meld is a full feature comparison software mainly used in GNOME. It is better than a lot of software listed here because

  1. it is free and open source. So you do not need to worry about the fee or security
  2. if not more powerful, it is as sophisticated as a lot of software which asks you a lot of money
  3. it is user-friendly and does not involve complex configuration or typing command in the terminal. You should be able to use it immediately once you install it.

The part that it is not as good might be that it is developed under GTK. So sometimes it does not feel like nature MAC programs. Besides, the old MAC versions were a little buggy. But the latest one 3.19.2 that I am currently using works great and I have never met an issue.

1
  • 3
    Also installation is easy with brew cask install meld Feb 21, 2020 at 19:42
7

If you are using Visual Studio Code, you can use the Compare Folders extension on the marketplace.

You open up a folder/project in Visual Studio Code, then select the two folders for compare. Right click and choose the new extension menu item.

It will bring up a new tab where it has differences in common files, a list of the files that are only in the first folder, and a list of files that are only in the second folder. It will use the built-in diff tool from Visual Studio Code.

1
  • Compare Folders extension is even better than DiffMerge
    – 0xh8h
    May 10, 2023 at 7:25
4

I recently purchased a copy of Kaleidoscope (approx $40 US). It's a clean app.

vimdiff is also available via the commandline and is portable across most UNIXy domains.

3
  • I've been using Kaleidoscope for a few months now. Worth the price. It goes on sale occasionally.
    – Ian C.
    Mar 15, 2011 at 13:49
  • 1
    Kaleidoscope does not allow me to edit a file so that’s an additional requirement for me.
    – mathieug
    Jan 26, 2017 at 9:17
  • Price of Kaleidoscope in App Store in 2020: 74,99 eur
    – akauppi
    Jan 29, 2020 at 8:43
4

The diff tool that comes with Bare Bones Software's Text Wrangler has directory comparison, although it only shows which files are in both directories, and which are only in each of the directories. When you select a file that's in both you can edit by merging changes line by line with the click of a button. It doesn't let you move files though. You have to do this externally (eg via Finder).
I find it to be one of the better free options.

2
  • 1
    this is also in BBedit Free Mode (now that Text Wrangler is EOLed)
    – Alex
    Jul 15, 2021 at 8:11
  • Thanks @Alex I was going to update this page, but not using MacOS much now, and wanted to review that BBEdit features have the same limitations as I mentioned above for TextWrangler before updating
    – Jason S
    Jul 20, 2021 at 9:07
2

Changes app ($37.19) used to be my workforce for this. It's as good as Beyond Compare.

Note: I hope this QA is allowed to exist, though it's against at least SO norms to pitch for products. The need for a usable, intuitive, graphic directory comparison tool for macOS remains acute. Open source candidates have not reached the level of usability that the commercial tools provide.

2

If you know how to run Python, here is a script that I wrote some time ago to efficiently compare two directories.

Features:

  • it can compare tree structures and file changes (based on file size & MD5 hashes)
  • can turn off file comparison, showing only tree structure changes (very fast!)
  • can turn off file content comparison, relying only on file size changes (again, very fast)
  • can colorize the output for better readability.

And, naturally, can modify according to your needs, if you know how to program.

#!/usr/bin/env python3

'''
A script to recursively compare two directories (including file size and file hash changes)
Usage: python3 compare_dirs.py DIR1 DIR2
'''

import os, sys, hashlib

COMPARE_FILES = True            # should file sizes be compared if their names are the same?
MD5 = True                      # should file hash sums be compared if their names and sizes are the same?
COLORIZE = False                # colorization for bash (only Linux & Unix)

def md5sum(fn):
    hasher = hashlib.md5()
    with open(fn, 'rb') as f:
        hasher.update(f.read())
        return hasher.hexdigest()

WHITE, RED, GREEN = 15, 196, 46
fg = lambda text, color: "\33[38;5;" + str(color) + "m" + text + "\33[0m"

def compare_dirs(d1: "old directory name", d2: "new directory name"):
    def print_local(a, msg):
        text = '{} {} {}'.format('DIR ' if a[2] else 'FILE', a[1], msg)
        if COLORIZE:
            color = {'added': GREEN, 'removed': RED}.get(msg, WHITE)
            print(fg(text, color))
        else:
            print(text)
    # Ensure validity
    for d in [d1,d2]:
        if not os.path.isdir(d):
            raise ValueError("not a directory: " + d)
    # Get relative path
    l1 = [(fn, os.path.join(d1, fn)) for fn in os.listdir(d1)]
    l2 = [(fn, os.path.join(d2, fn)) for fn in os.listdir(d2)]
    # Determine type: directory or file?
    l1 = sorted([(fn, pth, os.path.isdir(pth)) for fn, pth in l1])
    l2 = sorted([(fn, pth, os.path.isdir(pth)) for fn, pth in l2])
    i1 = i2 = 0
    cnt = 0
    common_dirs = []
    while i1<len(l1) and i2<len(l2):
        if l1[i1][0] == l2[i2][0]:      # same name
            if l1[i1][2] == l2[i2][2]:  # same type
                if l1[i1][2]:           
                    # Pair of directories -> remember the name for recursion
                    common_dirs.append((l1[i1][1], l2[i2][1]))
                elif COMPARE_FILES:
                    # Pair of files -> compare their sizes
                    size1 = os.stat(l1[i1][1]).st_size
                    size2 = os.stat(l2[i2][1]).st_size
                    if size1!=size2:
                        print_local(l1[i1],'size changed: {:d} -> {:d}'.format(size1, size2))
                    elif MD5:
                        # Sizes are the same -> compare MD5 hashes
                        if md5sum(l1[i1][1])!=md5sum(l2[i2][1]):
                            print_local(l1[i1],'hash changed')
            else:
                print_local(l1[i1],'type changed')
            i1 += 1
            i2 += 1
        elif l1[i1][0]<l2[i2][0]:
            print_local(l1[i1],'removed')
            i1 += 1
        elif l1[i1][0]>l2[i2][0]:
            print_local(l2[i2],'added')
            i2 += 1
        cnt += 1
    while i1<len(l1):
        print_local(l1[i1],'removed')
        i1 += 1
        cnt += 1
    while i2<len(l2):
        print_local(l2[i2],'added')
        i2 += 1
        cnt += 1
    # Compare subfolders recursively
    for sdir1,sdir2 in common_dirs:
        cnt += compare_dirs(sdir1, sdir2)
    return cnt

if __name__=='__main__':
    print ('Comparing files {}abled'.format('en' if COMPARE_FILES else 'dis'))
    print ('MD5 checking {}abled'.format('en' if MD5 else 'dis'))
    print ('Colorization {}abled'.format('en' if COLORIZE else 'dis'))
    print (compare_dirs(sys.argv[1], sys.argv[2]), 'items compared')

Link to GitHub Gist.

NOTE: it will not work for the files or subdirectories which were moved to the iCloud.

2

FreeFileSync, an open-source, cross-platform app (Wikipedia page here), seems to do it.

You can run syncs from the command line or in batch, but it looks like folder comparison results are intended to be viewed in the GUI.

Does a good job of comparing files across folders, and has settings for integrating with file diff tools.

screenshot from Windows version

1

I use Folder Sync It costs $8.99 on the Mac App Store It works really nicely.

1

As it’s now free on MacOS (with paid upgrade for more features), I found that BBedit also does an interestingly usefull directory (and file) comparisons while merging.

0

I have been comparing large folder structures (DVDs) in the past and I had developed a command-line utility to do this. I have recently made the utility (CrcCheckCopy) free and cross-platform (MacOS and Windows).

CrcCheckCopy scans the source folder and creates a file containing the CRC stamps of all files. Then, this file is used to compare the target folder.

You can get it from here: https://www.starmessagesoftware.com/crccheckcopy Your feedback you be much appreciated.

-3

Easiest solution: Sync the files using Dropbox or similar, then just use WinMerge on Windows.

The FileMerge utility that ships with Xcode doesn't compare folders and doesn't do merge/editing.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .