Skip to main content

Comparing files

The diff program in Unix is very powerful. Here are some interesting options.

Show changes side-by-side

The changes can be shown side by side. This works well with a very wide terminal, but you can still get a good indication of what has changed by setting its output to a narrower terminal width.

diff -y -W 80 file1 file2

Two directories can also be recursively compared

diff -Naur dir1 dir2

Interactive merge

There is also an interactive command called sdiff to merge two files together to create a third file.

However, I think it is easier to use emerge mode in emacs.

FileMerge application on macOS

On macOS with Xcode installed, there is a FileMerge application.

It is found under Applications > XCode > Contents > Applications, or just search for “FileMerge” in Spotlight.