1CMP(P) POSIX Programmer's Manual CMP(P)
2
3
4
6 cmp - compare two files
7
9 cmp [ -l | -s ] file1 file2
10
12 The cmp utility shall compare two files. The cmp utility shall write no
13 output if the files are the same. Under default options, if they dif‐
14 fer, it shall write to standard output the byte and line number at
15 which the first difference occurred. Bytes and lines shall be numbered
16 beginning with 1.
17
19 The cmp utility shall conform to the Base Definitions volume of
20 IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
21
22 The following options shall be supported:
23
24 -l (Lowercase ell.) Write the byte number (decimal) and the differ‐
25 ing bytes (octal) for each difference.
26
27 -s Write nothing for differing files; return exit status only.
28
29
31 The following operands shall be supported:
32
33 file1 A pathname of the first file to be compared. If file1 is '-' ,
34 the standard input shall be used.
35
36 file2 A pathname of the second file to be compared. If file2 is '-' ,
37 the standard input shall be used.
38
39
40 If both file1 and file2 refer to standard input or refer to the same
41 FIFO special, block special, or character special file, the results are
42 undefined.
43
45 The standard input shall be used only if the file1 or file2 operand
46 refers to standard input. See the INPUT FILES section.
47
49 The input files can be any file type.
50
52 The following environment variables shall affect the execution of cmp:
53
54 LANG Provide a default value for the internationalization variables
55 that are unset or null. (See the Base Definitions volume of
56 IEEE Std 1003.1-2001, Section 8.2, Internationalization Vari‐
57 ables for the precedence of internationalization variables used
58 to determine the values of locale categories.)
59
60 LC_ALL If set to a non-empty string value, override the values of all
61 the other internationalization variables.
62
63 LC_CTYPE
64 Determine the locale for the interpretation of sequences of
65 bytes of text data as characters (for example, single-byte as
66 opposed to multi-byte characters in arguments).
67
68 LC_MESSAGES
69 Determine the locale that should be used to affect the format
70 and contents of diagnostic messages written to standard error
71 and informative messages written to standard output.
72
73 NLSPATH
74 Determine the location of message catalogs for the processing of
75 LC_MESSAGES .
76
77
79 Default.
80
82 In the POSIX locale, results of the comparison shall be written to
83 standard output. When no options are used, the format shall be:
84
85
86 "%s %s differ: char %d, line %d\n", file1, file2,
87 <byte number>, <line number>
88
89 When the -l option is used, the format shall be:
90
91
92 "%d %o %o\n", <byte number>, <differing byte>,
93 <differing byte>
94
95 for each byte that differs. The first <differing byte> number is from
96 file1 while the second is from file2. In both cases, <byte number>
97 shall be relative to the beginning of the file, beginning with 1.
98
99 No output shall be written to standard output when the -s option is
100 used.
101
103 The standard error shall be used only for diagnostic messages. If file1
104 and file2 are identical for the entire length of the shorter file, in
105 the POSIX locale the following diagnostic message shall be written,
106 unless the -s option is specified:
107
108
109 "cmp: EOF on %s%s\n", <name of shorter file>, <additional info>
110
111 The <additional info> field shall either be null or a string that
112 starts with a <blank> and contains no <newline>s. Some implementations
113 report on the number of lines in this case.
114
116 None.
117
119 None.
120
122 The following exit values shall be returned:
123
124 0 The files are identical.
125
126 1 The files are different; this includes the case where one file
127 is identical to the first part of the other.
128
129 >1 An error occurred.
130
131
133 Default.
134
135 The following sections are informative.
136
138 Although input files to cmp can be any type, the results might not be
139 what would be expected on character special device files or on file
140 types not described by the System Interfaces volume of
141 IEEE Std 1003.1-2001. Since this volume of IEEE Std 1003.1-2001 does
142 not specify the block size used when doing input, comparisons of char‐
143 acter special files need not compare all of the data in those files.
144
145 For files which are not text files, line numbers simply reflect the
146 presence of a <newline>, without any implication that the file is orga‐
147 nized into lines.
148
150 None.
151
153 The global language in Utility Description Defaults indicates that
154 using two mutually-exclusive options together produces unspecified
155 results. Some System V implementations consider the option usage:
156
157
158 cmp -l -s ...
159
160 to be an error. They also treat:
161
162
163 cmp -s -l ...
164
165 as if no options were specified. Both of these behaviors are considered
166 bugs, but are allowed.
167
168 The word char in the standard output format comes from historical
169 usage, even though it is actually a byte number. When cmp is supported
170 in other locales, implementations are encouraged to use the word byte
171 or its equivalent in another language. Users should not interpret this
172 difference to indicate that the functionality of the utility changed
173 between locales.
174
175 Some implementations report on the number of lines in the identical-
176 but-shorter file case. This is allowed by the inclusion of the <addi‐
177 tional info> fields in the output format. The restriction on having a
178 leading <blank> and no <newline>s is to make parsing for the filename
179 easier. It is recognized that some filenames containing white-space
180 characters make parsing difficult anyway, but the restriction does aid
181 programs used on systems where the names are predominantly well
182 behaved.
183
185 None.
186
188 comm , diff
189
191 Portions of this text are reprinted and reproduced in electronic form
192 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
193 -- Portable Operating System Interface (POSIX), The Open Group Base
194 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
195 Electrical and Electronics Engineers, Inc and The Open Group. In the
196 event of any discrepancy between this version and the original IEEE and
197 The Open Group Standard, the original IEEE and The Open Group Standard
198 is the referee document. The original Standard can be obtained online
199 at http://www.opengroup.org/unix/online.html .
200
201
202
203IEEE/The Open Group 2003 CMP(P)