|CMP(1P)||POSIX Programmer's Manual||CMP(1P)|
cmp [−l|−s] file1 file2
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.
- 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.
- 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.
"%s %s differ: char %d, line %d\n", file1, file2, <byte number>, <line number>
When the −l option is used, the format shall be:
"%d %o %o\n", <byte number>, <differing byte>, <differing byte>
for each byte that differs. The first <differing byte> number is from file1 while the second is from file2. In both cases, <byte number> shall be relative to the beginning of the file, beginning with 1.
No output shall be written to standard output when the −s option is used.
"cmp: EOF on %s%s\n", <name of shorter file>, <additional info>
The <additional info> field shall either be null or a string that starts with a <blank> and contains no <newline> characters. Some implementations report on the number of lines in this case.
- 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.
The following sections are informative.
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.
cmp −l −s ...
to be an error. They also treat:
cmp −s −l ...
as if no options were specified. Both of these behaviors are considered bugs, but are allowed.
The word char in the standard output format comes from historical usage, even though it is actually a byte number. When cmp is supported in other locales, implementations are encouraged to use the word byte or its equivalent in another language. Users should not interpret this difference to indicate that the functionality of the utility changed between locales.
Some implementations report on the number of lines in the identical-but-shorter file case. This is allowed by the inclusion of the <additional info> fields in the output format. The restriction on having a leading <blank> and no <newline> characters is to make parsing for the filename easier. It is recognized that some filenames containing white-space characters make parsing difficult anyway, but the restriction does aid programs used on systems where the names are predominantly well behaved.
The Base Definitions volume of POSIX.1‐2008, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines
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 https://www.kernel.org/doc/man-pages/reporting_bugs.html .
|2013||IEEE/The Open Group|