The cmp command compares files designated by the File1 and File2 parameters and writes the results to standard output. If you specify a - (minus sign) for either the File1 or File2 parameter, the cmp command reads standard input for that file. Only one file can be read from standard input. Under default conditions, the cmp command displays nothing if the files are the same. If they differ, the cmp command displays the byte and line number at which the first difference occurs. If the -l flag is specified and if one file is an initial subsequence of the other (that is, if the cmp command reads an end-of-file character in one file before finding any differences), the cmp command notes this. Normally, use the cmp command to compare non-text files and the diff command to compare text files.
This command returns the following exit values:
cmp prog.o.bak prog.oThis compares prog.o.bak and prog.o. If the files are identical, then a message is not displayed. If the files differ, then the location of the first difference is displayed; for example:
prog.o.bak prog.o differ: char 4, line 1If the message cmp: EOF on prog.o.bak is displayed, then the first part of prog.o is identical to prog.o.bak, but there is additional data in prog.o.
cmp -l prog.o.bak prog.oThis compares the files, and then displays the byte number (in decimal) and the differing bytes (in octal) for each difference. For example, if the fifth byte is octal 101 in prog.o.bak and 141 in prog.o, the cmp command displays:
5 101 141
cmp -s prog.c.bak prog.cThis gives an exit value of 0 if the files are identical, a value of 1 if different, or a value of 2 if an error occurs. This form of the command is normally used in shell procedures. For example:
if cmp -s prog.c.bak prog.c then echo No change fiThis partial shell procedure displays No change if the two files are identical.
/usr/bin/cmp | Contains the cmp command. |
The comm command, diff command, ksh command.
Files Overview in AIX Version 4.3 System User's Guide: Operating System and Devices.
Input and Output Redirection Overview. in AIX Version 4.3 System User's Guide: Operating System and Devices.