29 January 2021
1 min read

How to Diff Command Colorize Output on Linux

Diff is a command-line utility that helps users to visually compare differences between 2 files line by line on a Linux/Unix system. Colordiff utility is a Perl script that is an improved version of diff. It colorizes the output so that the differences between the files are clearly visible on the terminal.

In a nutshell, the diff command tool can be used to perform the following

1. View changes that exist between 2 versions of a file.

2. Draw comparisons between 2 program files

In this tutorial, you will learn how to colorize diff output on Linux using the help of colordiff commands.

How to install Colordiff  utility

Before we get to the ins and outs of using d colordiff, let’s first install it.

Install Colordiff on Ubuntu/Debian/Mint

To install the colordiff utility on Debian-based systems such as Ubuntu and Mint, open your terminal and run the command:

$ sudo apt install colordiff

Install Colordiff on RHEL/CentOS

To install colordiff on rpm distributions such as Hat and CentOS, run:

$ sudo yum install colordiff

Install Colordiff on Arch Linux

For Arch Linux and derivatives of Arch Linux such as Manjaro, run:

$ sudo pacman -S colordiff

Install Colordiff on FreeBSD and OpenBSD

To install  Colordiff  on FreeBSD, run the command:

$ sudo pkg install  colordiff

For OpenBSD execute:

$ pkg_add -v colordiff

How to diff colorize

The syntax for using the colordiff and diff commands is quite simple and straightforward.

Use the syntax

$  color diff file1 file2

For example,  I have created 2 files as shown

To check the differences that exist between the two files, run the command:

$  colordiff file1.txt file2.txt

Additionally, you can use the diff command and pipe the output to colordiff as shown:

or

$ diff -u file1.txt  file2.txt | colordiff

Alternatives to diff color

Another handy way you can use to compare files is by use of the grc command as shown:

$ grc diff file1.txt file2.txt

Another cool tool I found is Icdiff which is an improved colored diff.

You can install Icdiff using pip command, run:

$ pip install git+https://github.com/jeffkaufman/icdiff.git

Conclusion

In this tutorial, you learned how to colorize diff output with help of colordiff command-line utilities to compare files on the terminal in a colorized format. If the two files are identical, then no output is printed on the screen. To get more information about how those two utilities are used, simply visit the man diff and man colordiff.

Give us a shout and let us know how your experience went. Thank you.

Bobbin Zachariah

Bobbin Zachariah

Bobbin Zachariah is the editor-in-chief of Linoxide and has an experienced team of Linux enthusiastic authors who makes this blog awesome. Linoxide is one of the top 20 Linux Blog by whizlabs.

Leave a Reply

Your email address will not be published.

Previous Story

Ubuntu Change Hostname + Make it Permanent

Next Story

Basic Linux Commands You Should Know

Latest from Blog

Top 8 Reasons to Use Garuda Linux

Have you been going back and forth between multiple Linux flavors in search of an exciting experience? Or perhaps you are coming from a Windows or MAC environment and want to try

How to Rename Multiple Files in Linux

In a Linux system, you can easily rename a file using mv command. But, if you have multiple files which you want to rename, in this situation you need some extra tools

How to Install TensorFlow on Ubuntu 20.04

Tensorflow is an open-source platform for machine learning and artificial intelligence. It is developed by the Google Brain team. It contains tools, libraries, and community resources for developers to build ML powered
Go toTop