Compare two folder structures and list files which exist in both, but are different

finderterminal

I have a local working folder which mirrors part of a web server’s public folder. I usually work in the local copy and then auto-upload files to the server when saving. Trouble is, I’ve realised lately that a lot of files in my local files appear to be out of date, so whenever I save and upload a file, I’m potentially overwriting a newer version. This is obviously problematic, so I’d like to get all the out-of-date local files up to date.

The best way I can think of to do this is to download the entire public folder as it is and compare each file with my local copy, going manually through files with differences (by comparing them in Visual Studio Code). The public server folder has about 5GB of extra stuff that I don’t need (or want) in my local working folder, though, so I’d have to filter out the unwanted stuff first.

In other words, I’m looking for a way (GUI or terminal) to do the following:

  • Give two top-level directories as input
  • Iterate recursively through both directories and pick out files which exist in both (in the same relative location)
  • Compare each set of matched files and list the ones where the two files are not identical

Is there some reasonably non-complex way of doing this?

Best Answer

While I'm a big proponent of utilizing built in tools (+1 for nohillside's answer) rather than searching for the nearest app, from time to time I do find really invaluable applications. In this case, I found a graphical differencing and merging application called Meld.

Meld is a visual diff and merge tool targeted at developers. Meld helps you compare files, directories, and version controlled projects. It provides two- and three-way comparison of both files and directories, and has support for many popular version control systems.

Meld Screenshot

Meld is probably overkill for what you're looking to do, but not so much that it makes the software cumbersome to use. The best part is that it's free (as in beer).