PROLOGThis manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
NAMEcmp --- compare two files
cmp [-l|-s] file1 file2
DESCRIPTIONThe cmp utility shall compare two files. The cmp utility shall write no output if the files are the same. Under default options, if they differ, it shall write to standard output the byte and line number at which the first difference occurred. Bytes and lines shall be numbered beginning with 1.
OPTIONSThe cmp utility shall conform to the Base Definitions volume of POSIX.1-2008, Section 12.2, Utility Syntax Guidelines. The following options shall be supported:
- (Lowercase ell.) Write the byte number (decimal) and the differing bytes (octal) for each difference.
- Write nothing for differing files; return exit status only.
OPERANDSThe following operands shall be supported:
- A pathname of the first file to be compared. If file1 is '-', the standard input shall be used.
- A pathname of the second file to be compared. If file2 is '-', the standard input shall be used. If both file1 and file2 refer to standard input or refer to the same FIFO special, block special, or character special file, the results are undefined.
STDINThe standard input shall be used only if the file1 or file2 operand refers to standard input. See the INPUT FILES section.
INPUT FILESThe input files can be any file type.
ENVIRONMENT VARIABLESThe following environment variables shall affect the execution of cmp:
- Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1-2008, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)
- If set to a non-empty string value, override the values of all the other internationalization variables.
- Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments).
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output.
- Determine the location of message catalogs for the processing of LC_MESSAGES.
STDOUTIn the POSIX locale, results of the comparison shall be written to standard output. When no options are used, the format shall be:
"%s %s differ: char %d, line %d\n", file1, file2, <byte number>, <line number>
"%d %o %o\n", <byte number>, <differing byte>, <differing byte>
STDERRThe standard error shall be used only for diagnostic messages. If the -l option is used and file1 and file2 differ in length, or if the -s option is not used and file1 and file2 are identical for the entire length of the shorter file, in the POSIX locale the following diagnostic message shall be written:
"cmp: EOF on %s%s\n", <name of shorter file>, <additional info>
EXIT STATUSThe following exit values shall be returned:
- The files are identical.
- The files are different; this includes the case where one file is identical to the first part of the other.
- An error occurred.
CONSEQUENCES OF ERRORSDefault.
The following sections are informative.
APPLICATION USAGEAlthough input files to cmp can be any type, the results might not be what would be expected on character special device files or on file types not described by the System Interfaces volume of POSIX.1-2008. Since this volume of POSIX.1-2008 does not specify the block size used when doing input, comparisons of character special files need not compare all of the data in those files. For files which are not text files, line numbers simply reflect the presence of a <newline>, without any implication that the file is organized into lines.
RATIONALEThe global language in Section 1.4, Utility Description Defaults indicates that using two mutually-exclusive options together produces unspecified results. Some System V implementations consider the option usage:
cmp -l -s ...
cmp -s -l ...
SEE ALSOcomm, diff The Base Definitions volume of POSIX.1-2008, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines
COPYRIGHTPortions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, Copyright (C) 2013 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. (This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at www.unix.org/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see www.kernel.org/doc/man-pages/reporting_bugs.html .