How to find differences between files

Use diff to compare two files and output a difference report (sometimes called a "diff") containing the text that differs between two files. The difference report is formatted so that other tools can use it to make a file identical to the one it was compared with. To compare two files and output a difference report, give their names as arguments to diff.

To compare the files `manuscript.old' and `', type:

$ diff manuscript.old RET

The difference report is output to standard output; to save it to a file, redirect the output to the file to save to:

$ diff manuscript.old 62; manuscript.diff RET

In the preceding example, the difference report is saved to a file called `manuscript.diff'.The difference report is meant to be used with commands such as patch, in order to apply the differences to a file. See Info file `', node `Top', for more information on diff and the format of its output. To better see the difference between two files, use sdiff instead of diff; instead of giving a difference report, it outputs the files in two columns, side by side, separated by spaces. Lines that differ in the files are separated by `|'; lines that appear only in the first file end with a `<', and lines that appear only in the
second file are preceded with a `>'. · To peruse the files `laurel' and `hardy' side by side on the screen, with any differences indicated between columns, type:

$ sdiff laurel hardy | less RET

To output the difference between three separate files, use diff3.To output a difference report for files `larry', `curly', and `moe', and output it in a file called `stooges', type:

$ diff3 larry curly moe 62; stooges RET

Posted on: 16/12/2009

If you want to leave a comment please Login or Register