1CMP(1P)                    POSIX Programmer's Manual                   CMP(1P)
2
3
4

PROLOG

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

NAME

12       cmp - compare two files
13

SYNOPSIS

15       cmp [ -l | -s ] file1 file2
16

DESCRIPTION

18       The cmp utility shall compare two files. The cmp utility shall write no
19       output  if  the files are the same. Under default options, if they dif‐
20       fer, it shall write to standard output the  byte  and  line  number  at
21       which the first difference occurred.  Bytes and lines shall be numbered
22       beginning with 1.
23

OPTIONS

25       The cmp utility  shall  conform  to  the  Base  Definitions  volume  of
26       IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
27
28       The following options shall be supported:
29
30       -l     (Lowercase ell.) Write the byte number (decimal) and the differ‐
31              ing bytes (octal) for each difference.
32
33       -s     Write nothing for differing files; return exit status only.
34
35

OPERANDS

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
46       If both file1 and file2 refer to standard input or refer  to  the  same
47       FIFO special, block special, or character special file, the results are
48       undefined.
49

STDIN

51       The standard input shall be used only if the  file1  or  file2  operand
52       refers to standard input. See the INPUT FILES section.
53

INPUT FILES

55       The input files can be any file type.
56

ENVIRONMENT VARIABLES

58       The following environment variables shall affect the execution of cmp:
59
60       LANG   Provide  a  default value for the internationalization variables
61              that are unset or null. (See  the  Base  Definitions  volume  of
62              IEEE Std 1003.1-2001,  Section  8.2,  Internationalization Vari‐
63              ables for the precedence of internationalization variables  used
64              to determine the values of locale categories.)
65
66       LC_ALL If  set  to a non-empty string value, override the values of all
67              the other internationalization variables.
68
69       LC_CTYPE
70              Determine the locale for  the  interpretation  of  sequences  of
71              bytes  of  text  data as characters (for example, single-byte as
72              opposed to multi-byte characters in arguments).
73
74       LC_MESSAGES
75              Determine the locale that should be used to  affect  the  format
76              and  contents  of  diagnostic messages written to standard error
77              and informative messages written to standard output.
78
79       NLSPATH
80              Determine the location of message catalogs for the processing of
81              LC_MESSAGES .
82
83

ASYNCHRONOUS EVENTS

85       Default.
86

STDOUT

88       In  the  POSIX  locale,  results  of the comparison shall be written to
89       standard output. When no options are used, the format shall be:
90
91
92              "%s %s differ: char %d, line %d\n", file1, file2,
93                  <byte number>, <line number>
94
95       When the -l option is used, the format shall be:
96
97
98              "%d %o %o\n", <byte number>, <differing byte>,
99                  <differing byte>
100
101       for each byte that differs. The first <differing byte> number  is  from
102       file1  while  the  second  is  from file2. In both cases, <byte number>
103       shall be relative to the beginning of the file, beginning with 1.
104
105       No output shall be written to standard output when  the  -s  option  is
106       used.
107

STDERR

109       The standard error shall be used only for diagnostic messages. If file1
110       and file2 are identical for the entire length of the shorter  file,  in
111       the  POSIX  locale  the  following diagnostic message shall be written,
112       unless the -s option is specified:
113
114
115              "cmp: EOF on %s%s\n", <name of shorter file>, <additional info>
116
117       The <additional info> field shall either  be  null  or  a  string  that
118       starts  with a <blank> and contains no <newline>s. Some implementations
119       report on the number of lines in this case.
120

OUTPUT FILES

122       None.
123

EXTENDED DESCRIPTION

125       None.
126

EXIT STATUS

128       The following exit values shall be returned:
129
130        0     The files are identical.
131
132        1     The files are different; this includes the case where  one  file
133              is identical to the first part of the other.
134
135       >1     An error occurred.
136
137

CONSEQUENCES OF ERRORS

139       Default.
140
141       The following sections are informative.
142

APPLICATION USAGE

144       Although  input  files to cmp can be any type, the results might not be
145       what would be expected on character special device  files  or  on  file
146       types    not   described   by   the   System   Interfaces   volume   of
147       IEEE Std 1003.1-2001. Since this volume  of  IEEE Std 1003.1-2001  does
148       not  specify the block size used when doing input, comparisons of char‐
149       acter special files need not compare all of the data in those files.
150
151       For files which are not text files, line  numbers  simply  reflect  the
152       presence of a <newline>, without any implication that the file is orga‐
153       nized into lines.
154

EXAMPLES

156       None.
157

RATIONALE

159       The global language in  Utility  Description  Defaults  indicates  that
160       using  two  mutually-exclusive  options  together  produces unspecified
161       results.  Some System V implementations consider the option usage:
162
163
164              cmp -l -s ...
165
166       to be an error. They also treat:
167
168
169              cmp -s -l ...
170
171       as if no options were specified. Both of these behaviors are considered
172       bugs, but are allowed.
173
174       The  word  char  in  the  standard  output format comes from historical
175       usage, even though it is actually a byte number. When cmp is  supported
176       in  other  locales, implementations are encouraged to use the word byte
177       or its equivalent in another language. Users should not interpret  this
178       difference  to  indicate  that the functionality of the utility changed
179       between locales.
180
181       Some implementations report on the number of lines  in  the  identical-
182       but-shorter  file  case. This is allowed by the inclusion of the <addi‐
183       tional info> fields in the output format. The restriction on  having  a
184       leading  <blank>  and no <newline>s is to make parsing for the filename
185       easier. It is recognized that  some  filenames  containing  white-space
186       characters  make parsing difficult anyway, but the restriction does aid
187       programs used  on  systems  where  the  names  are  predominantly  well
188       behaved.
189

FUTURE DIRECTIONS

191       None.
192

SEE ALSO

194       comm, diff
195
197       Portions  of  this text are reprinted and reproduced in electronic form
198       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
199       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
200       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
201       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
202       event of any discrepancy between this version and the original IEEE and
203       The  Open Group Standard, the original IEEE and The Open Group Standard
204       is the referee document. The original Standard can be  obtained  online
205       at http://www.opengroup.org/unix/online.html .
206
207
208
209IEEE/The Open Group                  2003                              CMP(1P)
Impressum