1diff(1)                          User Commands                         diff(1)
2
3
4

NAME

6       diff - compare two files
7

SYNOPSIS

9       diff [-bitw] [-c | -e | -f | -h | -n | -u] file1 file2
10
11
12       diff [-bitw] [-C number | -U number] file1 file2
13
14
15       diff [-bitw] [-D string] file1 file2
16
17
18       diff [-bitw] [-c | -e | -f | -h | -n | -u] [-l] [-r] [-s]
19            [-S name] directory1 directory2
20
21

DESCRIPTION

23       The diff utility will compare the contents of file1 and file2 and write
24       to standard output a list of changes necessary to  convert  file1  into
25       file2.  This list should be minimal. Except in rare circumstances, diff
26       finds a smallest sufficient set of file differences. No output will  be
27       produced if the files are identical.
28
29
30       The normal output contains lines of these forms:
31
32         n1 a n3,n4
33         n1,n2 d n3
34         n1,n2 c n3,n4
35
36
37
38
39       where  n1 and n2 represent lines file1 and n3 and n4 represent lines in
40       file2 These lines resemble ed(1) commands to convert file1 to file2. By
41       exchanging  a  for  d  and  reading backward, file2 can be converted to
42       file1. As in ed, identical pairs, where n1=n2 or n3=n4, are abbreviated
43       as a single number.
44
45
46       Following  each  of these lines come all the lines that are affected in
47       the first file flagged by `<', then all the lines that are affected  in
48       the second file flagged by `>'.
49

OPTIONS

51       The following options are supported:
52
53       -b     Ignores  trailing  blanks  (spaces  and  tabs)  and treats other
54              strings of blanks as equivalent.
55
56
57       -i     Ignores the case of letters. For example, `A' will compare equal
58              to `a'.
59
60
61       -t     Expands TAB characters in output lines. Normal or -c output adds
62              character(s) to the front of each line that may adversely affect
63              the indentation of the original source lines and make the output
64              lines difficult to interpret.  This  option  will  preserve  the
65              original source's indentation.
66
67
68       -w     Ignores  all  blanks  (SPACE  and TAB characters) and treats all
69              other strings of blanks as equivalent. For example, `if ( a == b
70              )' will compare equal to `if(a==b)'.
71
72
73
74       The following options are mutually exclusive:
75
76       -c            Produces  a  listing  of  differences with three lines of
77                     context. With this  option,  output  format  is  modified
78                     slightly.  That  is, output begins with identification of
79                     the files involved and their creation  dates,  then  each
80                     change is separated by a line with a dozen *'s. The lines
81                     removed from file1 are marked with '—'. The  lines  added
82                     to  file2 are marked '+'. Lines that are changed from one
83                     file to the other are marked in both files with '!'.
84
85
86       -C number     Produces a listing of differences identical to that  pro‐
87                     duced by -c with number lines of context.
88
89
90       -D string     Creates  a  merged version of file1 and file2 with C pre‐
91                     processor controls included so that a compilation of  the
92                     result without defining string is equivalent to compiling
93                     file1, while defining string will yield file2.
94
95
96       -e            Produces a script of only a, c, and d  commands  for  the
97                     editor  ed, which will recreate file2 from file1. In con‐
98                     nection with the -e option, the following  shell  program
99                     may  help  maintain  multiple versions of a file. Only an
100                     ancestral file ($1) and a chain of version-to-version  ed
101                     scripts  ($2,$3,...)  made  by  diff  need  be on hand. A
102                     ``latest version'' appears on the standard output.
103
104                       (shift; cat $*; echo a´1,$p') | ed − $1
105
106
107
108
109       -f           Produces a similar script, not  useful  with  ed,  in  the
110                    opposite order.
111
112
113       -h           Does  a fast, half-hearted job. It works only when changed
114                    stretches are short and well separated, but does  work  on
115                    files of unlimited length. Options -c, -C, -D, -e, -f, and
116                    -n are unavailable with -h. diff  does  not  descend  into
117                    directories with this option.
118
119
120       -n           Produces a script similar to -e, but in the opposite order
121                    and with a count of changed lines on each insert or delete
122                    command.
123
124
125       -u           Produces a listing of differences with three lines of con‐
126                    text. The output is similar to  that  of  the  -c  option,
127                    except  that the context is "unified". Removed and changed
128                    lines in file1 are marked by a '-' while  lines  added  or
129                    changed  in  file2  are  marked by a '+'. Both versions of
130                    changed lines appear in the output, while added,  removed,
131                    and  context lines appear only once. The identification of
132                    file1 and file2 is different, with "−−−" and  "+++"  being
133                    printed  where  "***"  and  "−−−" would appear with the -c
134                    option. Each change is separated by a line of the form
135
136                      @@ -n1,n2 +n3,n4 @@
137
138
139
140
141       -U number    Produces a listing of differences identical to  that  pro‐
142                    duced by -u with number lines of context.
143
144
145
146       The following options are used for comparing directories:
147
148       -l          Produces  output in long format. Before the diff, each text
149                   file is piped through pr(1) to paginate it.  Other  differ‐
150                   ences  are  remembered  and  summarized after all text file
151                   differences are reported.
152
153
154       -r          Applies diff recursively to common  subdirectories  encoun‐
155                   tered.
156
157
158       -s          Reports  files  that  are  identical. These identical files
159                   would not otherwise be mentioned.
160
161
162       -S name     Starts a directory diff in the middle, beginning  with  the
163                   file name.
164
165

OPERANDS

167       The following operands are supported:
168
169       file1          A  path  name  of a file or directory to be compared. If
170       file2          either file1 or file2 is , the standard input  will  be
171                      used in its place.
172
173
174       directory1     A path name of a directory to be compared.
175       directory2
176
177
178       If  only one of file1 and file2 is a directory, diff will be applied to
179       the non-directory file and the file contained  in  the  directory  file
180       with  a  filename  that  is  the same as the last component of the non-
181       directory file.
182

USAGE

184       See largefile(5) for the description  of  the  behavior  of  diff  when
185       encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
186

EXAMPLES

188       Example 1 Typical output of the diff command
189
190
191       In  the  following  command, dir1 is a directory containing a directory
192       named x, dir2 is a directory containing a directory named x, dir1/x and
193       dir2/x  both  contain  files named date.out, and dir2/x contains a file
194       named y:
195
196
197         example% diff -r dir1 dir2
198         Common subdirectories: dir1/x and dir2/x
199
200         Only in dir2/x: y
201
202         diff -r dir1/x/date.out dir2/x/date.out
203
204         1c1
205
206         < Mon Jul  2 13:12:16 PDT 1990
207
208         ---
209
210         > Tue Jun 19 21:41:39 PDT 1990
211
212
213

ENVIRONMENT VARIABLES

215       See environ(5) for descriptions of the following environment  variables
216       that affect the execution of diff: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES,
217       LC_TIME, and NLSPATH.
218
219       TZ     Determines the locale for affecting the timezone used for calcu‐
220              lating file timestamps written with the -C and -c options.
221
222

EXIT STATUS

224       The following exit values are returned:
225
226       0      No differences were found.
227
228
229       1      Differences were found.
230
231
232       >1     An error occurred.
233
234

FILES

236       /tmp/d?????        temporary file used for comparison
237
238
239       /usr/lib/diffh     executable file for -h option
240
241

ATTRIBUTES

243       See attributes(5) for descriptions of the following attributes:
244
245
246
247
248       ┌─────────────────────────────┬─────────────────────────────┐
249       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
250       ├─────────────────────────────┼─────────────────────────────┤
251       │Availability                 │SUNWesu                      │
252       ├─────────────────────────────┼─────────────────────────────┤
253       │CSI                          │Enabled                      │
254       ├─────────────────────────────┼─────────────────────────────┤
255       │Interface Stability          │Standard                     │
256       └─────────────────────────────┴─────────────────────────────┘
257

SEE ALSO

259       bdiff(1),   cmp(1),   comm(1),   dircmp(1),   ed(1),  pr(1),  sdiff(1),
260       attributes(5), environ(5), largefile(5), standards(5)
261

NOTES

263       Editing scripts produced under the -e or -f  options  are  naive  about
264       creating lines consisting of a single period (.).
265
266
267       Missing NEWLINE at end of file indicates that the last line of the file
268       in question did not have a NEWLINE. If the lines  are  different,  they
269       will  be  flagged and output, although the output will seem to indicate
270       they are the same.
271
272
273
274SunOS 5.11                        22 Sep 2004                          diff(1)
Impressum