how to

How to compare 2 files or directories in Linux Ubuntu

 

Here’s how to compare 2 files in Linux and output the difference or compare files in two directories. If you want to recursively compare two directories in Linux, read this blog.

See the difference between two directories in Linux

Meld is a tool for comparing two or more than two files and directories, and checking the differences between them on screen. Meld shows the differences between two or three files (or two or three directories) and allows you to edit the content – you can move content between them or edit the files manually.

This is very useful for comparing revision control system changes.

To install Meld on Debian, Ubuntu and Mint systems, run the following command:

$ sudo apt install meld         

Once installed, open the meld application from the terminal (use meld command) or from the Ubuntu application panel. Once opened, you can start comparing new files by selecting the menu item File ▸ New….

When you compare two files or directories, the application allows you to compare two or three text files side by side. The differences between the files will be highlighted to make it easier to see the changes.

On the left and right sides of the merge window are colored blocks that show the differences between the two files.

Note that each colored block represents a section that is inserted, deleted, modified, or in conflict between your files, depending on the block color used.

When comparing a folder or directories, Meld uses various color and text formats to tell you how it differs from the corresponding files/folders.

For example, if you see a regular font, it means the file/folder is the same in all folders being compared.

Similarly, other folder comparison formats are used:

  1. Italic: These files are different in different folders, but after applying text filters, these files are identical.
  2. Blue and Bold: Shows modified ones. These files differ in the compared folders.
  3. Green and Bold: New folder or files. This file/folder exists in this folder, but does not exist in others.
  4. Text in gray with a line in the middle: Missing. This file/folder does not exist in this folder, but does exist in one of the others.
  5. Bright red with yellow background and bold font: An error occurred while comparing this file.

You can also use join via the command line or terminal.

  1. For two-way or three-way file comparisons, run Meld with the command meld file1 file2 or meld file1 file2 file3, respectively.
  2. For two- or three-way directory comparisons, run Meld with meld dir1 dir2 or meld dir1 dir2 dir3.

For more help, use the meld –help command.

 

Related Articles

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.

Back to top button