Linux Basics: colordiff, An Alternative To The diff Command
Dear Linux geeks,
In this article I will teach you how to use a very useful tool that can be used to compare files line by line. I find it easy to use and recommend it to Linux geeks that want to move their skills to the next level.
As many of unixmen readers may know, the diff command which comes installed by default in many Linux distributions is used to compare files line by line.
There are many options available in the diff command-line tool such as -r which is used to report when two files are the same, -i to ignore case differences in file contents, -E to ignore changes due to tab expansion and many others that we will cover in this tutorial.
Open a new terminal and use the vim or any text editor you like to create two text files in the Desktop directory that we will need to practice the diff command.
cd /home/oltjano/Desktop vim file1.txt vim file1.txt
Add the following text in the first file.
Then open the second file and add the text sh0wn below. Make sure to save the changes in both cases as we need the files to have text so we can compare them by using the diff command-line utility.
After you have created the file, the diff command line utility can be used as shown below to compare the two files with each other line by line and find the differences between them.
diff file1.txt file2.txt
After running the above command I get the following output printed in my Linux terminal.
2d1 < 13
As you guys can see the diff utility is performing very well. It detected the difference between the two files we created in the beginning of this tutorial and gave us information by printing it as standard output.
You can also paginate the output with the help of the -l option like shown below.
diff -l file1.txt file2.txt
It passes the output through `pr‘ to paginate it. But I like my output nice and shiny so I use the colordiff tool which is a tool that is used to colorize the diff output.
color-diff is available in the default repositories of Ubuntu, so the apt-get command-line tool can help me to install it in my own system.
Type the following command to install colordiff in your Ubuntu system.
sudo apt-get install colordiff
You can install the colordiff utility in rpm operating systems using the RPM Package Manager by running the following command in your terminal.
yum install colordiff
According to the man page the colordiff tool has been tested various flavors of Linux and under OpenBSD, but should be broadly portable to other systems. It makes use of ANSI colors.
But, what is the difference between diff and colordiff?
The only difference that I know is that colordiff produces the same output as diff but with colored syntax highlighting. I like the colored syntax very much and find both tools very useful when I need to compare two files, see the changes between one version of a file or compare two configuration or program files.
The following commands make use of the colordiff tool.
colordiff file1.txt file2.txt
But if you are geeky like me, you can use a pipeline and make use of both diff and colordiff tools.
diff file1.txt file2.txt | colordiff
Like us on Facebook
We need your assistance to stay live
This week Top Posts
- Top Things To Do After Installing Ubuntu 13.10 'Saucy Salamander' : Ubuntu 13.10 Saucy Salamander will be released on coming October 17th with many new salient featur...0 comments |
- Wow! Linux Foundation To Offer Free Linux Course This Summer Worth $2,400 on EdX : Wow! Early last week it was all over the internet, if you haven't heard it yet then this is the t...0 comments |
- Grive: An Unofficial, Open Source Linux Client For Google Drive : A couple of months before, we have featured a Linux client for Google Drive named Syncdrive, which w...1 comment |
- How To Upgrade From Ubuntu 13.04 Raring To Ubuntu 13.10 Saucy Salamander : Ubuntu 13.10 Saucy will be released on October 17th. Hope it will come with lot of improvements and ...0 comments |
- Install LAMP Server (Apache, MySQL or MariaDB, PHP) On Ubuntu 13.10 : Updated January 12, 2014 LAMP is a combination of operating system and open-source software stack. ...0 comments |
- How To "Fix E: Could not open file /var/lib/dpkg/status" : QUESTION: I get the following error when I use sudo apt-get update: E: Could not open file /var/...0 comments |
- Install Sublime Text 3 In Fedora Easily With Fedy
- Grive: An Unofficial, Open Source Linux Client For Google Drive
- Install nSnake Game In Terminal
- How To “Fix E: Could not open file /var/lib/dpkg/status”
- Wow! Linux Foundation To Offer Free Linux Course This Summer Worth $2,400 on EdX
- Fedora 21 Scheduled For Release In October
- Install Uget Download Manager In Ubuntu, Fedora, Debian
- Download Elementary OS ‘Luna’ Official Wallpapers
- Install Power Commands 0.1.5 On Ubuntu 14.04/13.10/12.10/12.04
- 5 Android Apps that’s Going to Make Running Your Business Less Stressful
This work by unixmen.com is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Copyright © 2008-2013 Unixmen.com .