Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ cmp(1) — AIX PS/2 1.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

comm

diff

sh, Rsh



CMP(1,C)                    AIX Commands Reference                     CMP(1,C)



-------------------------------------------------------------------------------
cmp



PURPOSE

Compares two files.

SYNTAX


       +--------+
cmp ---| one of |-- file1 -- file2 --|
       | +----+ |
       +-| -l |-+
         | -s |
         +----+


DESCRIPTION

The cmp command compares file1 and file2 and writes the results to standard
output.  If you specify a - (minus) for file1, the cmp command reads 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 where the first difference occurs.  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 command notes this.
Normally, you use the cmp command to compare non-text files and the diff
command to compare text files.

FLAGS

-l    Displays, for each difference, the byte number in decimal and the
      differing bytes in octal.

-s    Returns only an exit value.  (0 indicates identical files; 1 indicates
      different files; 2 indicates inaccessible file or a missing argument).

EXAMPLES

  1. To determine whether two files are identical:

      cmp  prog.o.bak  prog.o

    This command compares "prog.o.bak" and "prog.o".  If the files are
    identical, a message is not displayed.  If the files differ, the location
    of the first difference is displayed.  For instance:

      prog.o.bak  prog.o  differ:  char  5,  line  1




Processed November 8, 1990         CMP(1,C)                                   1





CMP(1,C)                    AIX Commands Reference                     CMP(1,C)



    If the message "cmp: EOF on prog.o.bak" is displayed, the first part of the
    file "prog.o" is identical to the file "prog.o.bak", but there is
    additional data in the "prog.o" file to compare.

  2. To display each pair of bytes that differ:

      cmp  -l  prog.o.bak  prog.o

    This command 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 the file "prog.o.bak" and
    "141" in the file "prog.o", "cmp" displays:

      5  101  141

  3. To compare two files without writing any messages:

      cmp  -s  prog.c.bak  prog.c

    This command issues an exit value of "0" if the files are identical, a "1"
    if different, or a "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
      fi

    This partial shell procedure displays "No change" if the two files are
    identical.  See page sh-19 for details about the if command.

RELATED INFORMATION

See the following commands:  "comm,"  "diff," and  "sh, Rsh."





















Processed November 8, 1990         CMP(1,C)                                   2



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026