From LQWiki
Jump to: navigation, search

diff is a tool for comparing two input files and informing the user either via the standard output or a file as to the differences between them. It supports both ASCII and Binary comparisons allowing you to check for differences and similarities in both text/source files and compiled binaries. It's primary application is for use with the patch tool, allowing you to merge two source code files based on the output of a diff comparison.


To view two files side-by-side, make a wide terminal window and run this:

$ diff -W163 --side-by-side file1 file2 |less

The center column will indicate the differences (see man page).

The most often used diff options for sending patches to open source projects (including linux kernel patches) are:

$ diff -up $ORIG_FILE $NEW_FILE > my-patch.diff

Or for multiple files/directories:

$ diff -uprN $ORIG_DIR $NEW_DIR > my-patch.diff


Provided by the GNU Diffutils: man page

See also

External links