User Commands diff(1) NAME diff - display line-by-line differences between pairs of text files SYNOPSIS diff [ -bitw ] [-c | -e | -f | -h | -n ] _f_i_l_e_1 _f_i_l_e_2 diff [ -bitw ] [ -C _n_u_m_b_e_r ] _f_i_l_e_1 _f_i_l_e_2 diff [ -bitw ] [ -D _s_t_r_i_n_g ] _f_i_l_e_1 _f_i_l_e_2 diff [ -bitw ] [-c | -e | -f | -h | -n ] [ -l ] [ -r ] [ -s ] [ -S _n_a_m_e ] _d_i_r_e_c_t_o_r_y_1 _d_i_r_e_c_t_o_r_y_2 DESCRIPTION The diff utility will compare the contents of _f_i_l_e_1 and _f_i_l_e_2 and write to standard output a list of changes neces- sary to convert _f_i_l_e_1 into _f_i_l_e_2. This list should be minimal. No output will be produced if the files are identi- cal. The normal output contains lines of these forms: _n_1_7 a _n_3,_n_4_n_1,_n_2 d _n_3_n_1,_n_2 c _n_3,_n_4 where _n_1 and _n_2 represent lines _f_i_l_e_1 and _n_3 and _n_4 represent lines in _f_i_l_e_2 These lines resemble ed(1) commands to convert _f_i_l_e_1 to _f_i_l_e_2. By exchanging a for d and reading backward, _f_i_l_e_2 can be converted to _f_i_l_e_1. As in ed , ident- ical pairs, where _n_1=_n_2 or _n_3=_n_4, are abbreviated as a sin- gle 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 `>'. OPTIONS -b Ignores trailing blanks (spaces and tabs) and treats other strings of blanks as equivalent. -i Ignores the case of letters; for example, `A' will compare equal to `a'. -t Expands 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 source's indentation. -w Ignores all blanks (SPACE and TAB characters) and treats all other strings of blanks as equivalent; for example, `if ( a == b )' will compare equal to SunOS 5.7 Last change: 20 Dec 1996 1 User Commands diff(1) `if(a==b)'. The following options are mutually exclusive: -c Produces a listing of differences with three lines of context. With this option output format is modified slightly: output begins with identifica- tion of the files involved and their creation dates, then each change is separated by a line with a dozen *'s. The lines removed from _f_i_l_e_1 are marked with '-'; those added to _f_i_l_e_2 are marked '+'. Lines that are changed from one file to the other are marked in both files with '!'. -C _n_u_m_b_e_r Produces a listing of differences identical to that produced by -c with _n_u_m_b_e_r lines of context. -e Produces a script of only a, c, and d commands for the editor ed , which will recreate _f_i_l_e_2 from _f_i_l_e_1. 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 Except in rare circumstances, diff finds a smallest suffi- cient set of file differences. -f Produces a similar script, not useful with ed , in the opposite order. -h Does 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. -n Produces a script similar to -e, but in the oppo- site order and with a count of changed lines on each insert or delete command. -D _s_t_r_i_n_g Creates a merged version of _f_i_l_e_1 and _f_i_l_e_2 with C preprocessor controls included so that a compila- tion of the result without defining _s_t_r_i_n_g is equivalent to compiling _f_i_l_e_1, while defining _s_t_r_i_n_g will yield _f_i_l_e_2. SunOS 5.7 Last change: 20 Dec 1996 2 User Commands diff(1) The following options are used for comparing directories: -l Produce output in long format. Before the diff , each text file is piped through pr(1) to paginate it. Other differences are remembered and summar- ized after all text file differences are reported. -r Applies diff recursively to common subdirectories encountered. -s Reports files that are the identical; these would not otherwise be mentioned. -S _n_a_m_e Starts a directory diff in the middle, beginning with the file _n_a_m_e. OPERANDS The following operands are supported: _f_i_l_e_1, _f_i_l_e_2 A path name of a file or directory to be compared. If either _f_i_l_e_1 or _f_i_l_e_2 is -, the standard input will be used in its place. _d_i_r_e_c_t_o_r_y_1, _d_i_r_e_c_t_o_r_y_2 A path name of a directory to be compared. If only one of _f_i_l_e_1 and _f_i_l_e_2 is a directory, diff will be applied to the non-directory file and the file contained in the directory file with a filename that is the same as the last component of the non-directory file. USAGE See largefile(5) for the description of the behavior of diff when encountering files greater than or equal to 2 Gbyte ( 2 **31 bytes). EXAMPLES Example 1: Example of the diff command. If dir1 is a directory containing a directory named x, dir2 is a directory containing a directory named x, dir1/x and dir2/x both contain files named date.out, and dir2/x con- tains a file named y, the command: example% diff -r dir1 dir2 could produce output similar to: Common subdirectories: dir1/x and dir2/x Only in dir2/x: y SunOS 5.7 Last change: 20 Dec 1996 3 User Commands diff(1) diff -r dir1/x/date.out dir2/x/date.out 1c1 < Mon Jul 2 13:12:16 PDT 1990 --- > Tue Jun 19 21:41:39 PDT 1990 ENVIRONMENT VARIABLES See environ(5) for descriptions of the following environment variables that affect the execution of diff : LC_CTYPE, LC_MESSAGES, LC_TIME, and NLSPATH. TZ Determine the locale for affecting the timezone used for calculating file timestamps written with the -C and -c options. EXIT STATUS The following exit values are returned: 0 No differences were found. 1 Differences were found. >1 An error occurred. FILES /tmp/d????? temporary file used for comparison /usr/lib/diffh executable file for -h option ATTRIBUTES See attributes(5) for descriptions of the following attri- butes: ____________________________________________________________ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |______________________________|______________________________| | Availability | SUNWesu | |______________________________|______________________________| | CSI | Enabled | |______________________________|______________________________| SEE ALSO bdiff(1), cmp(1), comm(1), dircmp(1), ed(1), pr(1), sdiff( 1), attributes(5), environ(5), largefile(5) NOTES SunOS 5.7 Last change: 20 Dec 1996 4 User Commands diff(1) Editing scripts produced under the -e or -f options are naive about creating lines consisting of a single period (.). Missing NEWLINE at end of file indicates that the last line of the file in question did not have a NEWLINE. If the lines are different, they will be flagged and output; although the output will seem to indicate they are the same. SunOS 5.7 Last change: 20 Dec 1996 5