Technology and General Blog

The “diff” command in Linux is made use of to evaluate two data files to glance up their discrepancies. Even so, numerous people confuse this command with the “cmp” command. It is various from the “cmp” command because it also offers you with all the variations that can be produced to both of those the information for producing them equivalent. This posting will display you a number of examples of applying the “diff” command in Linux.

“diff” Command Syntax and its Assistance Guide in Linux

The “diff” command in Linux can be made use of with the pursuing syntax:

$ diff [option] File1 File2

In this article, “option” can be changed with the parameters that can be employed with this command, whereas “File1” and “File2” symbolize the two data files to be when compared.

You can glance by all the parameters that are out there with this command by accessing its help guide with the command revealed beneath:

The assist guide of the “diff” command is as follows:

“diff” Command Examples in Linux

“diff” command can be blended with diverse parameters for comparing any two supplied data files. We have made the pursuing three examples to illustrate its use. Nonetheless, just before likely via these examples, we would like to exhibit you the contents of the two files that we will use in all of these examples. We have simply just applied the “cat” command to display the contents of these two files on the terminal, as revealed in the impression down below:

Case in point 1: Using the “diff” Command without having any Solutions
If you want to exhibit the output of the “diff” command in a typical format, then you can use it without the need of any selections as follows:

We have changed File1 with Checklist.txt and File2 with List2.txt.

The dissimilarities amongst our two documents, together with the modifications that are desired to have out to make them both equally similar, are revealed in the output down below:

Illustration 2: Working with the “diff” Command to Produce the Output in the Context Manner
The context mode of the “diff” command will allow you to watch additional info connected to the specified data files and the improvements needed to make them similar. We can use this manner in the adhering to way:

You can visualize from the output of this command that the modification date and time of both the data files are also displayed together with the alterations that are essential to be made.

Example 3: Employing the “diff” Command to Produce the Output in the Unified Mode
The unified mode of the “diff” command is very substantially very similar to the context method on the other hand, the only variance is that it avoids exhibiting redundant info. To use this method, we will have to execute the command demonstrated down below:

You can visualize from the output of this command that only appropriate and exceptional facts from the two the files is remaining displayed on the terminal. In distinction, all the redundant facts current in both the files has been omitted. To confirm this distinction, you can evaluate this output with the output of Case in point # 2.


This article threw light-weight on applying the “diff” command in Linux to compare two data files and advise all the variations that can be designed to the two the documents to make them equivalent. What’s more, it also spelled out the difference among the “cmp” and the “diff” command in Linux.

Leave a Reply

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