mirror of https://github.com/mkerrisk/man-pages
242 lines
7.0 KiB
Groff
242 lines
7.0 KiB
Groff
|
.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
|
||
|
.TH "CMP" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
|
||
|
.\" cmp
|
||
|
.SH NAME
|
||
|
cmp \- compare two files
|
||
|
.SH SYNOPSIS
|
||
|
.LP
|
||
|
\fBcmp\fP \fB[\fP \fB-l | -s\fP \fB]\fP \fIfile1 file2\fP
|
||
|
.SH DESCRIPTION
|
||
|
.LP
|
||
|
The \fIcmp\fP utility shall compare two files. The \fIcmp\fP 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.
|
||
|
.SH OPTIONS
|
||
|
.LP
|
||
|
The \fIcmp\fP utility shall conform to the Base Definitions volume
|
||
|
of IEEE\ Std\ 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
|
||
|
.LP
|
||
|
The following options shall be supported:
|
||
|
.TP 7
|
||
|
\fB-l\fP
|
||
|
(Lowercase ell.) Write the byte number (decimal) and the differing
|
||
|
bytes (octal) for each difference.
|
||
|
.TP 7
|
||
|
\fB-s\fP
|
||
|
Write nothing for differing files; return exit status only.
|
||
|
.sp
|
||
|
.SH OPERANDS
|
||
|
.LP
|
||
|
The following operands shall be supported:
|
||
|
.TP 7
|
||
|
\fIfile1\fP
|
||
|
A pathname of the first file to be compared. If \fIfile1\fP is \fB'-'\fP
|
||
|
, the standard input shall be used.
|
||
|
.TP 7
|
||
|
\fIfile2\fP
|
||
|
A pathname of the second file to be compared. If \fIfile2\fP is \fB'-'\fP
|
||
|
, the standard input shall be used.
|
||
|
.sp
|
||
|
.LP
|
||
|
If both \fIfile1\fP and \fIfile2\fP refer to standard input or refer
|
||
|
to the same FIFO special, block special, or character
|
||
|
special file, the results are undefined.
|
||
|
.SH STDIN
|
||
|
.LP
|
||
|
The standard input shall be used only if the \fIfile1\fP or \fIfile2\fP
|
||
|
operand refers to standard input. See the INPUT FILES
|
||
|
section.
|
||
|
.SH INPUT FILES
|
||
|
.LP
|
||
|
The input files can be any file type.
|
||
|
.SH ENVIRONMENT VARIABLES
|
||
|
.LP
|
||
|
The following environment variables shall affect the execution of
|
||
|
\fIcmp\fP:
|
||
|
.TP 7
|
||
|
\fILANG\fP
|
||
|
Provide a default value for the internationalization variables that
|
||
|
are unset or null. (See the Base Definitions volume of
|
||
|
IEEE\ Std\ 1003.1-2001, Section 8.2, Internationalization Variables
|
||
|
for
|
||
|
the precedence of internationalization variables used to determine
|
||
|
the values of locale categories.)
|
||
|
.TP 7
|
||
|
\fILC_ALL\fP
|
||
|
If set to a non-empty string value, override the values of all the
|
||
|
other internationalization variables.
|
||
|
.TP 7
|
||
|
\fILC_CTYPE\fP
|
||
|
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).
|
||
|
.TP 7
|
||
|
\fILC_MESSAGES\fP
|
||
|
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.
|
||
|
.TP 7
|
||
|
\fINLSPATH\fP
|
||
|
Determine the location of message catalogs for the processing of \fILC_MESSAGES
|
||
|
\&.\fP
|
||
|
.sp
|
||
|
.SH ASYNCHRONOUS EVENTS
|
||
|
.LP
|
||
|
Default.
|
||
|
.SH STDOUT
|
||
|
.LP
|
||
|
In the POSIX locale, results of the comparison shall be written to
|
||
|
standard output. When no options are used, the format shall
|
||
|
be:
|
||
|
.sp
|
||
|
.RS
|
||
|
.nf
|
||
|
|
||
|
\fB"%s %s differ: char %d, line %d\\n",\fP \fIfile1\fP\fB,\fP \fIfile2\fP\fB,
|
||
|
<\fP\fIbyte number\fP\fB>, <\fP\fIline number\fP\fB>
|
||
|
\fP
|
||
|
.fi
|
||
|
.RE
|
||
|
.LP
|
||
|
When the \fB-l\fP option is used, the format shall be:
|
||
|
.sp
|
||
|
.RS
|
||
|
.nf
|
||
|
|
||
|
\fB"%d %o %o\\n", <\fP\fIbyte number\fP\fB>, <\fP\fIdiffering byte\fP\fB>,
|
||
|
<\fP\fIdiffering byte\fP\fB>
|
||
|
\fP
|
||
|
.fi
|
||
|
.RE
|
||
|
.LP
|
||
|
for each byte that differs. The first <\fIdiffering\ byte\fP> number
|
||
|
is from \fIfile1\fP while the second is from
|
||
|
\fIfile2\fP. In both cases, <\fIbyte\ number\fP> shall be relative
|
||
|
to the beginning of the file, beginning with 1.
|
||
|
.LP
|
||
|
No output shall be written to standard output when the \fB-s\fP option
|
||
|
is used.
|
||
|
.SH STDERR
|
||
|
.LP
|
||
|
The standard error shall be used only for diagnostic messages. If
|
||
|
\fIfile1\fP and \fIfile2\fP are identical for the entire
|
||
|
length of the shorter file, in the POSIX locale the following diagnostic
|
||
|
message shall be written, unless the \fB-s\fP option is
|
||
|
specified:
|
||
|
.sp
|
||
|
.RS
|
||
|
.nf
|
||
|
|
||
|
\fB"cmp: EOF on %s%s\\n", <\fP\fIname of shorter file\fP\fB>, <\fP\fIadditional info\fP\fB>
|
||
|
\fP
|
||
|
.fi
|
||
|
.RE
|
||
|
.LP
|
||
|
The <\fIadditional\ info\fP> field shall either be null or a string
|
||
|
that starts with a <blank> and contains no
|
||
|
<newline>s. Some implementations report on the number of lines in
|
||
|
this case.
|
||
|
.SH OUTPUT FILES
|
||
|
.LP
|
||
|
None.
|
||
|
.SH EXTENDED DESCRIPTION
|
||
|
.LP
|
||
|
None.
|
||
|
.SH EXIT STATUS
|
||
|
.LP
|
||
|
The following exit values shall be returned:
|
||
|
.TP 7
|
||
|
\ 0
|
||
|
The files are identical.
|
||
|
.TP 7
|
||
|
\ 1
|
||
|
The files are different; this includes the case where one file is
|
||
|
identical to the first part of the other.
|
||
|
.TP 7
|
||
|
>1
|
||
|
An error occurred.
|
||
|
.sp
|
||
|
.SH CONSEQUENCES OF ERRORS
|
||
|
.LP
|
||
|
Default.
|
||
|
.LP
|
||
|
\fIThe following sections are informative.\fP
|
||
|
.SH APPLICATION USAGE
|
||
|
.LP
|
||
|
Although input files to \fIcmp\fP 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 IEEE\ Std\ 1003.1-2001. Since this volume of
|
||
|
IEEE\ Std\ 1003.1-2001 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.
|
||
|
.LP
|
||
|
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.
|
||
|
.SH EXAMPLES
|
||
|
.LP
|
||
|
None.
|
||
|
.SH RATIONALE
|
||
|
.LP
|
||
|
The global language in \fIUtility Description Defaults\fP indicates
|
||
|
that using two
|
||
|
mutually-exclusive options together produces unspecified results.
|
||
|
Some System V implementations consider the option usage:
|
||
|
.sp
|
||
|
.RS
|
||
|
.nf
|
||
|
|
||
|
\fBcmp -l -s ...
|
||
|
\fP
|
||
|
.fi
|
||
|
.RE
|
||
|
.LP
|
||
|
to be an error. They also treat:
|
||
|
.sp
|
||
|
.RS
|
||
|
.nf
|
||
|
|
||
|
\fBcmp -s -l ...
|
||
|
\fP
|
||
|
.fi
|
||
|
.RE
|
||
|
.LP
|
||
|
as if no options were specified. Both of these behaviors are considered
|
||
|
bugs, but are allowed.
|
||
|
.LP
|
||
|
The word \fBchar\fP in the standard output format comes from historical
|
||
|
usage, even though it is actually a byte number. When
|
||
|
\fIcmp\fP is supported in other locales, implementations are encouraged
|
||
|
to use the word \fIbyte\fP or its equivalent in another
|
||
|
language. Users should not interpret this difference to indicate that
|
||
|
the functionality of the utility changed between locales.
|
||
|
.LP
|
||
|
Some implementations report on the number of lines in the identical-but-shorter
|
||
|
file case. This is allowed by the inclusion of
|
||
|
the <\fIadditional\ info\fP> fields in the output format. The restriction
|
||
|
on having a leading <blank> and no
|
||
|
<newline>s 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.
|
||
|
.SH FUTURE DIRECTIONS
|
||
|
.LP
|
||
|
None.
|
||
|
.SH SEE ALSO
|
||
|
.LP
|
||
|
\fIcomm\fP , \fIdiff\fP
|
||
|
.SH COPYRIGHT
|
||
|
Portions of this text are reprinted and reproduced in electronic form
|
||
|
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
|
||
|
-- Portable Operating System Interface (POSIX), The Open Group Base
|
||
|
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
|
||
|
Electrical and Electronics Engineers, Inc and The Open Group. 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
|
||
|
http://www.opengroup.org/unix/online.html .
|