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

2009-09-17 595 words 3 mins read

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

What is interesting is that you can use &#8221;diff -u&#8221; to list the differences with &#8217;+&#8217; and &#8217;-&#8217; rather than sometimes confusing &#8217;>&#8217; and '<&#8217;.

An interesting article on finding the difference in files can be read <a href="http://docs.hp.com/en/5971-3502/5971-3502.pdf">here.

For reference:<h3 class="post-title entry-title"> <a set="yes" linkindex="1" href="http://amjith.blogspot.com/2007/07/visual-diff-tools-in-linux.html">Visual Diff Tools in Linux <div class="post-body entry-content"> <div style="text-align: center;">**\**This is a not a post about how to use diff and patch commands.****

<div style="text-align: center;"> <div style="text-align: justify;">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.

<span style="font-weight: bold;">Command Line:

<span style="color: rgb(51, 51, 255);">sdiff file-1 file-2

<a set="yes" linkindex="2" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://blog.amit-agarwal.co.in/wp-content/uploads/2009/09/sdiff.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://blog.amit-agarwal.co.in/wp-content/uploads/2009/09/sdiff1.png" alt="" id="BLOGGER_PHOTO_ID_5086514011316842866" border="0" />
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.

<span style="color: rgb(51, 51, 255);">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.

<a linkindex="7" href="http://www.guiffy.com/">Guiffy:<div style="text-align: center;"><a set="yes" linkindex="8" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://blog.amit-agarwal.co.in/wp-content/uploads/2009/09/Guiffy80Vista.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://blog.amit-agarwal.co.in/wp-content/uploads/2009/09/Guiffy80Vista1.jpg" alt="" id="BLOGGER_PHOTO_ID_5086509578910593314" border="0" />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&#8217;t feel like reviewing them (too ugly). 🙂

**Update:

<a linkindex="9" href="http://kdiff3.sourceforge.net/">kdiff3:<div style="text-align: center;"><a set="yes" linkindex="10" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://blog.amit-agarwal.co.in/wp-content/uploads/2009/09/dirmergebig.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://blog.amit-agarwal.co.in/wp-content/uploads/2009/09/dirmergebig1.png" alt="" id="BLOGGER_PHOTO_ID_5087073241828585858" border="0" />Taken from the kdiff3&#8217;s <a linkindex="11" href="http://kdiff3.sourceforge.net/">website.

<span style="color: rgb(102, 102, 102);">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: <a class="performancingtags" href="http://technorati.com/tag/Linux" rel="tag">Linux, <a class="performancingtags" href="http://technorati.com/tag/diff" rel="tag">diff, <a class="performancingtags" href="http://technorati.com/tag/sdiff" rel="tag">sdiff, <a class="performancingtags" href="http://technorati.com/tag/vimdiff" rel="tag">vimdiff, <a class="performancingtags" href="http://technorati.com/tag/" rel="tag">


Tags: diff Linux

Related Articles:


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

❮ top command with rc to make it more useful and beautiful. added mail and mail notification support on the blog. ❯

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it