Colordiff, colors the output of the diff command in the terminal

about colordiff

In the next article we are going to take a look at Colordiff. In case someone does not know it, diff is a utility for the command line and that it is very helpful for users when visually comparing the differences between 2 files. Colordiff is a Perl script, which is still an improved version of diff.

Colordiff is a container for diff, which produces the same output but colored, to improve the readability of the differences. Color schemes can be read from a central configuration file or from a local user file (~ / .colordiffrc). This utility uses ANSI colors.

Diff is a utility for file comparison. This generates the differences between two files, or the changes made in a certain file, comparing it with a previous version of the same file. It will show us the changes made per line in the text files, but without highlighting the differences.

Most implementations of diff they have remained seemingly unchanged since their inception. Modifications usually consist of improvements to the base algorithm, adding useful features to the command, and the design of new output formats., as is the case with Colordiff.

Install Colordiff on Ubuntu

The installation of this tool in Ubuntu is very simple. In Ubuntu / Debian / Mint, all you have to do is open a terminal (Ctrl + Alt + T) and use the following command:

icdiff working

sudo apt install colordiff

uninstall

If we want to eliminate this tool from our system, what we will have to do is open a terminal (Ctrl + Alt + T) and execute the command in it:

uninstall colordiff

sudo apt remove colordiff

Using Colordiff

When we want to use Colordiff, we are going to start by opening a terminal (Ctrl + Alt + T). Colordiff can be used where we would normally use diff, or pipe output to colordiff. First of all, it is a good idea to familiarize yourself with the syntax for using the colordiff and diff commands. This is pretty simple and straightforward:

colordiff archivo1 archivo2

To begin with in the following example we are going to create 2 files, as shown in the following screenshot:

basic creation of the sample files

Now for check the differences between the two files, in a terminal (Ctrl + Alt + T) we are going to use the command:

colordiff running

colordiff archivo1.txt archivo2.txt

As well we will have the possibility to use the diff command and channel its output to colordiff, as shown in the following command:

diff pipe colordiff

diff -u archivo1.txt archivo2.txt | colordiff

In these lines we have just seen how we can color the output of differences in the terminal, between two files with the help of Colordiff. With it we can compare files in the terminal and obtain results that are easier to read. If the two files are identical, no results will be printed on the screen.

If anyone needs help or more information about the possibilities offered by this utility, you can refer to the help it offers by typing in the terminal:

help colordiff

colordiff --help

For get in-depth information on how both diff and colordiff are used, users will have the possibility to visit man diff or the man page by colordiff.

Alternatives to Colordiff.

Another very useful way to compare files is by el grc command. If we do not have it available on our computer, we can install it easily by opening a terminal (Ctrl + Alt + T) and typing in it:

install grc

sudo apt install grc

Its syntax is very simple, as can be seen in the following example:

grc running

grc diff archivo1.txt archivo2.txt

For consult the help, in the terminal you will only have to use the command:

grc --help

Uninstall grc

Removing this program is as simple as installing it. We just have to open a terminal (Ctrl + Alt + T) and write:

sudo apt remove grc

Another available tool is icdiff. Installing it is as simple as opening a terminal (Ctrl + Alt + T) and using the command:

install icdiff with apt

sudo apt install icdiff

We can also opt for your version like snap pack. To install it, you will have to use the command:

install icdiff snap

sudo snap install icdiff

The syntax of this tool is as simple as the previous options seen during the article.

icdiff working

You can learn more about how to install this tool, how to use it or its available options in the project GitHub page.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.