Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ cmp(1) — Reliant UNIX 5.44c4

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

comm(1)

diff(1)

cmp(1)                                                               cmp(1)

NAME
     cmp - compare two files

SYNOPSIS
     cmp [-l] [-s] [--] file1 file2

DESCRIPTION
     The cmp command does a comparison of two files byte by byte (character
     by character). If the files differ, cmp reports the differences on
     standard output.

     If the files are identical, cmp remains silent.

OPTIONS
     No option specified:
          If the files are identical, cmp remains silent.

          If the files differ, cmp indicates the byte (character) and line
          number of the first difference that it detects between file1 and
          file2 as shown below:

          file1 file2 differ: char bytenumber, line linenumber

     -l   All differences are reported in the following form:

          bytenumber   byte(file1)   byte(file2)

          bytenumber represents the displacement of the difference from the
          beginning of the file. The first byte of the file is assigned
          number 1, and blanks are counted.

          bytenumber is given in decimal notation.

          The byte columns show the bytes which differ between file1 and
          file2 and are in octal notation. An ASCII table of octal-coded
          values is provided in ascii(5). If the files are identical, noth-
          ing is output.

     -s   cmp remains silent. The exit status value is returned but not
          automatically displayed on the screen. -s must not be used
          together with -l.

     --   If file1 begins with a dash (-), the end of the command-line
          options must be marked with --.

     file1 file2
          The names of the files that you wish to compare.

          -  If you use a dash - as the name for file1, cmp reads from
             standard input and compares your input with file2.





Page 1                       Reliant UNIX 5.44                Printed 11/98

cmp(1)                                                               cmp(1)

          -  If one of the two files ends before cmp can detect a differ-
             ence, cmp reports that the end of the file has been reached in
             the shorter file by issuing the following message:

             cmp: EOF on file

          -  If one character is missing in one of two otherwise identical
             files, cmp -l reports all following bytes as differences. This
             is due to the shift in character positions.

          -  The first character of a file is assigned bytenumber 1, not 0.

          -  Blanks and newline characters are included in the bytenumber
             count.

EXIT STATUS
     0   Files identical.

     1   Files differ.

     >1  Inaccessible file or missing argument.

ERROR MESSAGES

     cmp: cannot open file

     You do not have read permission for one of the files, or one of the
     files does not exist.

LOCALE
     The LCMESSAGES environment variable governs the language in which
     message texts are displayed. If LCMESSAGES is undefined or is defined
     as the null string, it defaults to the value of LANG. If LANG is like-
     wise undefined or null, the system acts as if it were not internation-
     alized.

     The LCALL environment variable governs the entire locale. LCALL
     takes precedence over all the other environment variables which affect
     internationalization.

EXAMPLES
     Example 1

     Compare two files and print the differing bytes (octal) and their
     bytenumber (decimal).

     $ echo 1 2 3 4 5 7 8 a >file1
     $ echo 1 2 3 4 5 6 9 a >file2
     $ cmp -l file1 file2
     11  67  66
     13  70  71
     $


Page 2                       Reliant UNIX 5.44                Printed 11/98

cmp(1)                                                               cmp(1)

     Example 2

     The shell script delete.eq compares two files and deletes one of them
     if they are identical.

     if cmp -s $1 $2
     then
       rm $2
     fi

     When you call the script with

     $ delete.eq file1 file2

     you pass file1 and file2 to it as positional operands. The -s option
     causes cmp to return the exit status. If the value of the exit status
     is 0 (= true), file2 is deleted; otherwise, it is retained.

SEE ALSO
     comm(1), diff(1).


































Page 3                       Reliant UNIX 5.44                Printed 11/98

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