Format
cmp [–Bblsx] [-W option[,option]...] file1
file2 [seek1 [seek2]]
Description
cmp compares
two files. If either file name is –, cmp reads
the standard input (stdin) for that file. By default, cmp begins
the comparison with the first byte of each file. If you specify either seek1
or seek2 (or both), cmp uses
it as a byte offset into file1 or file2 (respectively),
and comparison begins at that offset instead of at the beginning of
the files. The comparison continues, one byte at a time, until a difference
is found. At that point, the comparison ends and cmp displays
the byte and line number where the difference occurred. cmp numbers
bytes and lines beginning with 1.
Options
- –B
- Disables the automatic conversion of tagged files. This option
is ignored if the filecodeset or pgmcodeset options
(-W option) are specified.
- –b
- Compares single blocks at a time. Typically, cmp reads
large buffers of data into memory for comparison.
- –l
- Causes the comparison and display to continue to the end. However, mp does
not attempt any resynchronization. cmp displays
the byte number (in decimal) and the differing bytes (in octal format)
for each difference found.
- –s
- Suppresses output and returns a nonzero status if the files are
not identical.
- -W option[,option]...
- Specifies z/OS-specific options. The option keywords are case-sensitive. Possible
options are:
- filecodeset=codeset
- Performs text conversion from one code set to another when reading
from the file. The coded character set of the file is codeset. codeset can
be a code set name known to the system or a numeric coded character
set identifier (CCSID). Note that the command iconv -l lists
existing CCSIDs along with their corresponding code set names. The filecodeset and pgmcodeset options
can be used on files with any file tag.
If pgmcodeset is
specified but filecodeset is omitted, then
the default file code set is ISO8859-1 even if the file is tagged
with a different code set. If neither filecodeset nor pgmcodeset is
specified, text conversion will not occur unless automatic conversion
is enabled or the _TEXT_CONV environment variable indicates text conversion.
For more information about text conversion, see Controlling text conversion for z/OS UNIX shell commands.
If filecodeset or pgmcodeset is
specified, then automatic conversion is disabled for this command
invocation and the -B option is ignored
if it is also specified. See z/OS UNIX System Services Planning for
more information about automatic conversion.
When
specifying values for filecodeset, use the
values that Unicode Service supports. For more information about supported
code sets, see z/OS Unicode Services User's Guide and Reference.
- pgmcodeset=codeset
- Performs text conversion from one code set to another when reading
from the file. The coded character set of the program (command) is codeset. codeset can
be a code set name known to the system or a numeric coded character
set identifier (CCSID). Note that the command iconv -l lists
existing CCSIDs along with their corresponding code set names. The filecodeset and pgmcodeset options
can be used on files with any file tag.
If filecodeset is
specified but pgmcodeset is omitted, then
the default program code set is IBM-1047. If neither filecodeset nor pgmcodeset is
specified, text conversion will not occur unless automatic conversion
is enabled or the _TEXT_CONV environment variable indicates text conversion.
For more information about text conversion, see Controlling text conversion for z/OS UNIX shell commands.
If filecodeset or pgmcodeset is
specified, then automatic conversion is disabled for this command
invocation and the -B option is ignored
if it is also specified. See z/OS UNIX System Services Planning for
more information about automatic conversion.
Restriction: The
only supported values for pgmcodeset are
IBM-1047 and 1047.
- –x
- Displays the differing bytes shown by the –l option
in hexadecimal format. Typically, cmp displays
them in octal format.
Examples
- To compare two files and display the first byte and line number
of the difference:
cmp myFile01 myFile02
- To compare two text files containing ASCII characters and display
all the differences by byte number and octal byte format in EBCDIC,
assuming that:
- The text file is untagged and you do not want to tag it or enable
automatic conversion, and
- You cannot alter the tag (for example, you are displaying an untagged
public text file or a read-only text file):
cmp -l -W filecodeset=ISO8859-1,pgmcodeset=IBM-1047
myAsciiFile01 myAsciiFile02
- To compare two files and display the first byte and line number
of the difference, assuming that automatic conversion has been enabled
but the files are incorrectly tagged as UTF-8:
cmp -B myMisTaggedFile01 myMisTaggedFile02
Localization
cmp uses
the following localization environment variables:
- LANG
- LC_ALL
- LC_CTYPE
- LC_MESSAGES
- NLSPATH
See Localization for more
information.
Environment variables
cmp uses
the following environment variable:
- _TEXT_CONV
- Contains text conversion information for the command. The text
conversion information is not used when either the -B option
or the filecodeset or pgmcodeset option
(-W option) is specified. For more information
about text conversion, see Controlling text conversion for z/OS UNIX shell commands.
Exit values
- 0
- The files were identical
- 1
- The files were not identical
- 2
- Failure due to any of the following:
- The command-line option is not correct.
- The code set is not valid.
- 3
- Failure due to any of the following:
- An error opening or reading an input file
- Could not turn off automatic conversion
- Could not perform requested text conversion
Messages
Possible error messages include:
- EOF on filename
- cmp reached the end of the file on the
specified file before reaching the end of the file on the other file.
Portability
POSIX.2, X/Open Portability Guide, UNIX systems.
The –B, –b, –W and –x options
and the seek pointers are extensions of
the POSIX standard.
Related information
comm, diff, uniq