brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: diff -y shows two files side by side in the terminal

Diff
~/tips/tip-diff-y-side-by-side

diff -y -W 100 old.conf new.conf

Puts two versions next to each other in columns, which is easier to read for short config files.

The classic diff output with < and > takes some getting used to. For short files, two columns next to each other read much faster.

diff -y -W 100 old.conf new.conf

-y prints the old file on the left and the new one on the right. A | between the columns marks a changed line, < a line only on the left and > a line only on the right. -W sets the total width; the default is 130, which wraps badly on a narrow terminal, so I’d set it to the window width.

For longer files, add --suppress-common-lines, which hides the lines that are the same on both sides:

diff -y --suppress-common-lines -W 100 old.conf new.conf

On two small files that leaves just the changed line, b | B, instead of the whole file.

Long lines get cut off to fit the column, so a difference at the end of a long line can be invisible in this view. For wide files, diff -u is more reliable, or an editor with a diff mode. The side-by-side output also can’t be used as a patch. I see it as something to look at, not to keep.

Further reading: diff(1) manual page, GNU diffutils manual

More Diff tips diff -r -x .git -x '*.log' one two diff -Naur original/ changed/ > fix.patch patch -p1 --dry-run < ../fix.patch diff --strip-trailing-cr windows.txt unix.txt if ! diff -q /etc/nginx/nginx.conf /srv/backup/nginx.conf > /dev/null; then All Diff tips (12) All topics

Link