The diff command compares files line by line and displays a list of changes between two files. You can use diff command to:
- See the changes between one version of a file.
- Compare two configuration or program files.
- Create a patch file which can be applied with the Linux / Unix program patch.
diff Command Colorize Output On the Unix / Linux Command Line
colordiff is a wrapper for diff and produces the same output as diff but with coloured syntax highlighting at the command line to improve readability. colordiff has been tested on various flavours of Linux and under OpenBSD, but should be broadly portable to other systems.
How to install colordiff
The colordiff command packaged for many Linux distro, UNIX-like systems and *BSD distributions and other operating systems. Let us see how to install colordiff command.
Installing colordiff on a CentOS/RHEL
Fedora Linux install colordiff
Type the following dnf command:
$ sudo dnf install colordiff
Debian/Ubuntu/Mint Linux install colordiff to colorize output of diff
OpenBSD install colordiff
Simply type the pkg_add command:
# pkg_add -v colordiff
Update candidates: quirks-2.414 -> quirks-2.414 quirks-2.414 signed on 2018-03-28T14:24:37Z colordiff-1.0.18: ok Extracted 31057 from 31305
FreeBSD install colordiff
Run the pkg command as follows:
$ sudo pkg install colordiff
Updating FreeBSD repository catalogue... FreeBSD repository is up to date. All repositories are up to date. The following 1 package(s) will be affected (of 0 checked): New packages to be INSTALLED: colordiff: 1.0.18 Number of packages to be installed: 1 14 KiB to be downloaded. Proceed with this action? [y/N]: y [rsnapshot] [1/1] Fetching colordiff-1.0.18.txz: 100% 14 KiB 14.7kB/s 00:01 Checking integrity... done (0 conflicting) [rsnapshot] [1/1] Installing colordiff-1.0.18... [rsnapshot] [1/1] Extracting colordiff-1.0.18: 100%
macOS install colordiff
How do I use colordiff command?
The syntax is:
colordiff file1 file2
diff -u file1 file2 | colordiff
You can pipe the output to less command, using the -R or -r option which keeps the color escape sequences, otherwise displayed incorrectly or discarded by less:
diff -u file1 file2 | colordiff | less -R
Alternatives to colordiff command
Use remark command as follows:
diff file1 file2 | remark /usr/share/regex-markup/diff
You can also use the grc command:
grc diff file1 file2
GNU/Linux user can use the following syntax to colorize the output without install colordiff:
diff --color file1 file2
diff --color resolv.conf resolv.conf.saved
Another option is to use the vimdiff command to edit two or more versions of a file with Vim and show differences:
vimdiff file1 file2
viff resolv.conf resolv.conf.saved
You just learned how to use diff command to colorize output on the Unix / Linux, macOS and *BSD like systems. Use the following syntax to read man page for information about colordiff and diff command:
You can grab the source code of colordiff here.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
|Category||List of Unix and Linux commands|
|Firewall||Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04|
|Network Utilities||dig • host • ip • nmap|
|OpenVPN||CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04|
|Package Manager||apk • apt|
|Processes Management||bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time|
|Searching||grep • whereis • which|
|User Information||groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w|
|WireGuard VPN||Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04|