1CMP(1P) POSIX Programmer's Manual CMP(1P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 cmp — compare two files
14
16 cmp [−l|−s] file1 file2
17
19 The cmp utility shall compare two files. The cmp utility shall write no
20 output if the files are the same. Under default options, if they dif‐
21 fer, it shall write to standard output the byte and line number at
22 which the first difference occurred. Bytes and lines shall be numbered
23 beginning with 1.
24
26 The cmp utility shall conform to the Base Definitions volume of
27 POSIX.1‐2008, Section 12.2, Utility Syntax Guidelines.
28
29 The following options shall be supported:
30
31 −l (Lowercase ell.) Write the byte number (decimal) and the dif‐
32 fering bytes (octal) for each difference.
33
34 −s Write nothing for differing files; return exit status only.
35
37 The following operands shall be supported:
38
39 file1 A pathname of the first file to be compared. If file1 is '−',
40 the standard input shall be used.
41
42 file2 A pathname of the second file to be compared. If file2 is
43 '−', the standard input shall be used.
44
45 If both file1 and file2 refer to standard input or refer to the same
46 FIFO special, block special, or character special file, the results are
47 undefined.
48
50 The standard input shall be used only if the file1 or file2 operand
51 refers to standard input. See the INPUT FILES section.
52
54 The input files can be any file type.
55
57 The following environment variables shall affect the execution of cmp:
58
59 LANG Provide a default value for the internationalization vari‐
60 ables that are unset or null. (See the Base Definitions vol‐
61 ume of POSIX.1‐2008, Section 8.2, Internationalization Vari‐
62 ables for the precedence of internationalization variables
63 used to determine the values of locale categories.)
64
65 LC_ALL If set to a non-empty string value, override the values of
66 all the other internationalization variables.
67
68 LC_CTYPE Determine the locale for the interpretation of sequences of
69 bytes of text data as characters (for example, single-byte as
70 opposed to multi-byte characters in arguments).
71
72 LC_MESSAGES
73 Determine the locale that should be used to affect the format
74 and contents of diagnostic messages written to standard error
75 and informative messages written to standard output.
76
77 NLSPATH Determine the location of message catalogs for the processing
78 of LC_MESSAGES.
79
81 Default.
82
84 In the POSIX locale, results of the comparison shall be written to
85 standard output. When no options are used, the format shall be:
86
87 "%s %s differ: char %d, line %d\n", file1, file2,
88 <byte number>, <line number>
89
90 When the −l option is used, the format shall be:
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 the
104 −l option is used and file1 and file2 differ in length, or if the −s
105 option is not used and file1 and file2 are identical for the entire
106 length of the shorter file, in the POSIX locale the following diagnos‐
107 tic message shall be written:
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> characters. Some imple‐
113 mentations 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 is
127 identical to the first part of the other.
128
129 >1 An error occurred.
130
132 Default.
133
134 The following sections are informative.
135
137 Although input files to cmp can be any type, the results might not be
138 what would be expected on character special device files or on file
139 types not described by the System Interfaces volume of POSIX.1‐2008.
140 Since this volume of POSIX.1‐2008 does not specify the block size used
141 when doing input, comparisons of character special files need not com‐
142 pare all of the data in those files.
143
144 For files which are not text files, line numbers simply reflect the
145 presence of a <newline>, without any implication that the file is orga‐
146 nized into lines.
147
149 None.
150
152 The global language in Section 1.4, Utility Description Defaults indi‐
153 cates that using two mutually-exclusive options together produces
154 unspecified results. Some System V implementations consider the option
155 usage:
156
157 cmp −l −s ...
158
159 to be an error. They also treat:
160
161 cmp −s −l ...
162
163 as if no options were specified. Both of these behaviors are considered
164 bugs, but are allowed.
165
166 The word char in the standard output format comes from historical
167 usage, even though it is actually a byte number. When cmp is supported
168 in other locales, implementations are encouraged to use the word byte
169 or its equivalent in another language. Users should not interpret this
170 difference to indicate that the functionality of the utility changed
171 between locales.
172
173 Some implementations report on the number of lines in the identical-
174 but-shorter file case. This is allowed by the inclusion of the <addi‐
175 tional info> fields in the output format. The restriction on having a
176 leading <blank> and no <newline> characters is to make parsing for the
177 filename easier. It is recognized that some filenames containing white-
178 space characters make parsing difficult anyway, but the restriction
179 does aid programs used on systems where the names are predominantly
180 well behaved.
181
183 None.
184
186 comm, diff
187
188 The Base Definitions volume of POSIX.1‐2008, Chapter 8, Environment
189 Variables, Section 12.2, Utility Syntax Guidelines
190
192 Portions of this text are reprinted and reproduced in electronic form
193 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
194 -- Portable Operating System Interface (POSIX), The Open Group Base
195 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
196 cal and Electronics Engineers, Inc and The Open Group. (This is
197 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
198 event of any discrepancy between this version and the original IEEE and
199 The Open Group Standard, the original IEEE and The Open Group Standard
200 is the referee document. The original Standard can be obtained online
201 at http://www.unix.org/online.html .
202
203 Any typographical or formatting errors that appear in this page are
204 most likely to have been introduced during the conversion of the source
205 files to man page format. To report such errors, see https://www.ker‐
206 nel.org/doc/man-pages/reporting_bugs.html .
207
208
209
210IEEE/The Open Group 2013 CMP(1P)