Diff Linux command — Find the difference in files the easier way.

In Linux you can use diff command to find the differences in file.

What is interesting is that you can use \”diff -u\” to list the differences with \’+\’ and \’-\’ rather than sometimes confusing \’>\’ and \'<\’.

An interesting article on finding the difference in files can be read here.

For reference:

Visual Diff Tools in Linux

****This is a not a post about how to use diff and patch commands.****
Running the regular diff between two text files to see the differences is not so elegant for the human eye to decode. Luckily there are plenty of tools out there to make this easy.

Command Line:

sdiff file-1 file-2

\"\"
This is a much more elegant tool compared to diff, if you are looking for a quick command-line utility that shows the difference between two text files. While using it on big files, its better to pipe the output to less command.

sdiff file1 file2 | less

Disadvantage – this is a read-only output. No editing or merging is possible. But its a great tool for a quick visual inspection.


Update: Use sdiff -o out_file file1 file2 to interactively merge file1 and file2 and write the output into out_file. (Thanks to anonymous commenter)

vimdiff file-1 file-2

\"\"
This can open \”n\” number of files in a vertically split vim environment. This has color highlighting to specify the areas that differ in the file. Editing is possible. This is a complete vim-environment, so all the vim keys are usable.

Emacs:

M-x ediff-buffers
\"\"This is an emacs equivalent of vimdiff with copy to left, copy to right, merge changes and much more. This is a special ediff mode which has its own key bindings. Hit ? to get help on the keyboard shortcuts.

Colored highlighting for distinguishing differences. Easy navigation to diff regions.

A maximum of 3 files can be compared and merged. Both comand-line and gui mode are available.

Visual Tools:

Meld:

\"\"Image borrowed from Meld website

Can compare two or three files and allows editing. The differences are dynamically updated. This can work with version control systems like CVS, SVN etc. Folder comparison is possible.

Guiffy:

\"\"Screenshot borrowed from Guiffy website.

Multi-platform visual diff and merge tool. Has a three-pane view for comparing two-files and the third pane to view the merged output file. Works in Window, Linux and Mac OS X. Folder comparison is possible.

I am sure there are more tools out there (such as xxdiff) but I don\’t feel like reviewing them (too ugly). 🙂

**Update:

kdiff3:

\"\"Taken from the kdiff3\’s website.

Thanks to the anonymous commenter. An excellent tool from the kde bunch. I loved it. Has the option to compare 2 or 3 files. Has an extra window pane to look at the out of the merged file. Directory differences and merging are possible.

Technorati Tags: Linux, diff, sdiff, vimdiff,

About Amit Agarwal