1 CMP(1)                           User Commands                          CMP(1)
   2 
   3 NAME
   4      cmp - compare two files
   5 
   6 SYNOPSIS
   7      cmp [-bcdilns] file1 file2 [skip1 [skip2]]
   8 
   9 DESCRIPTION
  10      The cmp utility compares two files.  cmp writes no output if the files
  11      are the same.  Under default options, if they differ, it writes to
  12      standard output the byte and line numbers at which the first difference
  13      occurred.  Bytes and lines are numbered beginning with 1.  skip1 and
  14      skip2 are initial byte offsets into file1 and file2 respectively, and are
  15      specified in bytes or can be given with a suffix of k for kilobytes or m
  16      for megabytes.
  17 
  18      If either file1 or file2 is a dash (-), cmp uses standard input starting
  19      at the current location.
  20 
  21 OPTIONS
  22      The following options are supported:
  23 
  24      -b, --print-bytes
  25                    Print differing bytes as 3-digit octal values.
  26 
  27      -c, --print-chars
  28                    Print differing bytes as follows:
  29 
  30                    o       non-space printable characters as themselves;
  31 
  32                    o       space and control characters as ^ followed by a
  33                            letter of the alphabet;
  34 
  35                    o       characters with the high bit set as the lower 7-bit
  36                            character prefixed by M^ for 7-bit space and non-
  37                            printable characters, and M- for all other
  38                            characters.  If the 7-bit character encoding is not
  39                            ASCII then the characters are converted to ASCII to
  40                            determine whether the high bit is set and, if set,
  41                            it is cleared and converted back to the native
  42                            encoding.  Multibyte characters in the current
  43                            locale are treated as printable characters.
  44 
  45      -d differences, --differences=differences
  46                    Print at most differences differences using -l (--verbose)
  47                    output format.  If differences is 0 then this is equivalent
  48                    to passing the -s or --silent option.
  49 
  50      -i skip1[:skip2, --skip=skip1[:skip2, --ignore-initial=skip1[:skip2]]]
  51                    Skip the first skip1 bytes in file1 and the first skip2
  52                    bytes in file2.  If skip2 is omitted then skip1 is used for
  53                    that value.  The default value is 0:0.
  54 
  55      -l, --verbose
  56                    Write the byte number (decimal) and the differing bytes
  57                    (octal) for each difference.
  58 
  59      -n count, --count=count, --bytes=count
  60                    Compare at most count bytes.
  61 
  62      -s, --silent -, --quiet
  63                    Write nothing for differing files.  Return exit status
  64                    only.
  65 
  66 OPERANDS
  67      The following operands are supported:
  68 
  69      file1         A path name of the first file to be compared.  If file1 is
  70                    -, the standard input is used.
  71 
  72      file2         A path name of the second file to be compared.  If file2 is
  73                    -, the standard input is used.
  74 
  75      skip1         The number of initial bytes from file1 to skip before
  76                    beginning the comparison.
  77 
  78      skip2         The number of initial bytes from file2 to skip before
  79                    beginning the comparison.  If skip1 is specified but skip2
  80                    is not, then the value of skip1 is also implicitly used for
  81                    skip2.
  82 
  83      If both file1 and file2 refer to standard input or refer to the same
  84      FIFO, block or character special file, an error results.
  85 
  86      skip values are specified in bytes, or can be suffixed with k (for
  87      kilobytes) or m (for megabytes.)
  88 
  89 EXIT STATUS
  90      The following exit values are returned:
  91 
  92      0       The files or portions compared are identical.
  93 
  94      1       The files or portions compared are different.
  95 
  96      >1           An error ocurred.
  97 
  98 EXAMPLES
  99      Example 1 Comparing Files Byte for Byte
 100              The following example does a byte for byte comparison of file1
 101              and file2, skipping the first 1024 bytes in file2 before starting
 102              the comparison.
 103 
 104              $ cmp file1 file2 0 1024
 105 
 106 ENVIRONMENT VARIABLES
 107      See environ(5) for descriptions of the following environment variables
 108      that affect the execution of cmp: LANG, LC_ALL, LC_TYPE, LC_MESSAGES,
 109      LC_NUMERIC, and NLSPATH.
 110 
 111 INTERFACE STABILITY
 112      The command line interface of cmp is Committed.  The output of cmp is
 113      Standard.
 114 
 115 SEE ALSO
 116      comm(1), diff(1), attributes(5), environ(5), largefile(5), standards(5)
 117 
 118 illumos                        February 9, 2021                        illumos