DIFF(1) DIFF(1) NAME diff - differential file and directory comparator SYNOPSIS diff [-lrs] [-Sname] [-cefhn] [-xpat] [-biwt] dir1 dir2 diff [-cefhn] [-biwt] file1 file2 diff [-Dstring] [-biw] file1 file2 GNU diff options: diff [-#] [-aBdHNpqTuv] [-Cnum] [-Fexp] [-Iexp] [-Llab] DESCRIPTION If both arguments are directories, diff sorts the contents of the directories by name, and then runs the regular file diff algorithm (described below) on text files which are different. Binary files which differ (unless -a is specified), common subdirectories, and files which appear in only one directory are listed. Options when comparing directories are: -l long output format; each text file diff is piped through pr(1) to paginate it, other differences are remembered and summarized after all text file differences are reported. -r causes application of diff recursively to common subdirectories encountered. -s causes diff to report files which are the same, which are otherwise not mentioned. -Sname starts a directory diff in the middle beginning with file name. -xpat adds pat to a list of regular expressions. There can be several -xpat options. Any directory or file (base) name matching one of the patterns is skipped. The special characters available in the pattern pat are similar to those used in egrep(1). For example, the following command will ignore all "hidden" files and all RCS archives: diff -r '-x^\.' '-x,v$' foo bar When run on regular files, and when comparing text files which differ during directory comparison, diff tells what lines must be changed in the files to bring them into agreement. Except in rare circumstances, diff finds a smallest sufficient set of file differences. If neither file1 nor file2 is a directory, then either may be given as `-', in which case the standard input is used. If file1 is a directory, then a file in that directory whose file-name is the same as the file-name of file2 is used (and vice versa). If both file1 and file2 are directories, then files (or files and directories with -r) with identical names are compared. There are several options for output format; the default output format contains lines of these forms: n1 a n3,n4 n1,n2 d n3 n1,n2 c n3,n4 These lines resemble ed commands to convert file1 into file2. The numbers after the letters pertain to file2. In fact, by exchanging `a' for `d' and reading backward one may ascertain equally how to convert file2 into file1. As in ed, identical pairs where n1 = n2 or n3 = n4 are abbreviated as a single number. 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 `>'. Except for -b, -w, -i or -t which may be given with any of the others, the following options are mutually exclusive: -e produces a script of a, c and d commands for the editor ed, which will recreate file2 from file1. In connection with -e, the following shell program may help maintain multiple versions of a file. Only an ancestral file ($1) and a chain of version- to-version ed scripts ($2,$3,...) made by diff need be on hand. A `latest version' appears on the standard output. (shift; cat $*; echo '1,$p') | ed - $1 Extra commands are added to the output when comparing directories with -e, so that the result is a sh(1) script for converting text files which are common to the two directories from their state in dir1 to their state in dir2. -f produces a script similar to that of -e, not useful with ed, and in the opposite order. -n produces a script similar to that of -e, but in the opposite order and with a count of changed lines on each insert or delete command. This is the form used by the RCS commands for storing a revision change. -c produces a diff with 3 lines of context. Use the -Cnum option to specify the number of lines. With -c the output format is modified slightly: the output beginning with identification of the files involved and their creation dates and 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 which are changed from one file to the other are marked in both files with `! '. Changes which lie within <context> lines of each other are grouped together on output. -h has no affect. It is present for compatibility with odiff(1). -Dstring causes diff to create a merged version of file1 and file2 on the standard output, 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. -b causes trailing blanks (spaces and tabs) to be ignored, and other strings of blanks to compare equal. -w is similar to -b but causes whitespace (blanks and tabs) to be totally ignored. E.g., ``if ( a == b )'' will compare equal to ``if(a==b)''. -i ignores the case of letters. E.g., ``A'' will compare equal to ``a''. -t will expand tabs in output lines. Normal or -c output adds character(s) to the front of each line which may foul up the indentation of the original source lines and make the output listing difficult to interpret. This option will preserve the original source's indentation. GNU DIFF OPTIONS -# Show # lines (an integer) of context. This option does not specify an output format by itself; it has no effect unless it is combined with -c or -u. -a Treat all files as text and compare them line-by-line, even if they do not appear to be text -B Ignore changes that just insert or delete blank lines. -Cnum Use the context output format, showing lines (an integer) lines of context -d Change the algorithm to find a guaranteed minimal set of changes. This makes diff slower (sometimes much slower). -Fexp In context and unified format, for each hunk of differences, show some of the last preceding line that matches exp. -H Use heuristics to speed handling of large files that have numerous scattered small changes -Iexp Ignore changes that just insert or delete lines that match exp. -Llab Use lab instead of the pathname in the context format and unified format headers -N In directory comparison, if a file is found in only one directory, treat it as present but empty in the other directory. -p Show which C function each change is in. -q Report only whether the files differ, not the details of the differences. -T Output a tab rather than a space before the text of a line in normal or context format. This causes the alignment of tabs in the line to look normal. -u Use the unified output format -v Display the version string. FILES /usr/bin/odiff executable for odiff. /bin/diff executable for GNU derived diff. /bin/pr executed by the -l option. SEE ALSO bdiff(1), cc(1), cmp(1), comm(1), odiff(1), diff3(1), ed(1), DIFFsource(5) DIAGNOSTICS Exit status is 0 for no differences, 1 for some differences, 2 for trouble. PERFORMANCE The GNU derived diff and older BSD derived odiff use different algorithms. If the two files to be compared fit in main memory, then diff is faster, but if they don't fit, diff can cause severe paging. The odiff algorithm uses a small, fixed amount of memory even on large files. The multiple pass algorithm of odiff is up to two or three times slower than diff, on files that fit in memory, but can be many times faster on files that don't fit. The diff command automatically invokes the odiff (searching for odiff along $PATH) on files that have a combined size larger than one-fourth of memory size, if no GNU specific diff options were specified. If that fails, then diff silently does the work itself. You can force either variant: specifying -H always gets diff, specifying odiff always gets odiff. Page 4