Command Prompt for Windows

Command DIFF


Display line-by-line differences between pairs of text files.



DIFF [/bitw] [/c | /h] file1 file2
DIFF [/bitw] [/C number] file1 file2
DIFF [/bitw] [/D string ] file1 file2
DIFF [/bitw] [/c | /h] [/r] [/s] [/S name] directory1 directory2
/bIgnores trailing blanks (spaces and tabs) and treats other strings of blanks as equivalent.
/iIgnores the case of letters; for example, `A' will compare equal to `a'.
/tExpands TAB characters in output lines. Normal or /c output adds character(s) to the front of each line that may adversely affect the indentation of the original source lines and make the output lines difficult to interpret. This option will preserve the original sources indentation.
/wIgnores all blanks (SPACE and TAB characters) and treats all other strings of blanks as equivalent; for example, `if ( a == b )' will compare equal to `if(a==b)'.

The following options are mutually exclusive:-

/cProduces a listing of differences with three lines of context. With this option output format is modified slightly: output begins with identification of the files involved and their creation dates, then each change is separated by a line with a dozen *s. The lines removed from file1 are marked with '-'; those added to file2 are marked '+'. Lines that are changed from one file to the other are marked in both files with '!'.
/C numberProduces a listing of differences identical to that produced by /c with number lines of context.
/hDoes a fast, half-hearted job. It works only when changed stretches are short and well separated, but does work on files of unlimited length. Options /c, /e, /f, and /n are unavailable with /h. diff does not descend into directories with this option.
/D stringCreates a merged version of file1 and file2 with C preprocessor controls included so that a compilation of the result without defining string is equivalent to compiling file1, while defining string will yield file2.

The following options are used for comparing directories:-

/rApplies diff recursively to common subdirectories encountered.
/sReports files that are the identical; these would not otherwise be mentioned.
/S nameStarts a directory diff in the middle, beginning with the file name.


Diff tells what lines must be changed in two files to bring them into agreement. Following each of these lines come all the lines that are affected in the first file flagged by <, then all the lines that are affected in the second file flagged by >.

If file1 (or file2) is a directory, then a file in that directory with the name file2 (or file1) is used.

Except in rare circumstances, diff finds a smallest sufficient set of file differences.

Missing newline at end of file indicates that the last line of file X did not have a new-line. If the lines are different, they will be flagged and output; although the output will seem to indicate they are the same.

DIFF is an ANSI only command and does not support UNICODE.