1 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
   2 .\" permission to reproduce portions of its copyrighted documentation.
   3 .\" Original documentation from The Open Group can be obtained online at
   4 .\" http://www.opengroup.org/bookstore/.
   5 .\"
   6 .\" The Institute of Electrical and Electronics Engineers and The Open
   7 .\" Group, have given us permission to reprint portions of their
   8 .\" documentation.
   9 .\"
  10 .\" In the following statement, the phrase ``this text'' refers to portions
  11 .\" of the system documentation.
  12 .\"
  13 .\" Portions of this text are reprinted and reproduced in electronic form
  14 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
  15 .\" Standard for Information Technology -- Portable Operating System
  16 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
  17 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
  18 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
  19 .\" between these versions and the original IEEE and The Open Group
  20 .\" Standard, the original IEEE and The Open Group Standard is the referee
  21 .\" document.  The original Standard can be obtained online at
  22 .\" http://www.opengroup.org/unix/online.html.
  23 .\"
  24 .\" This notice shall appear on any product containing this material.
  25 .\"
  26 .\" The contents of this file are subject to the terms of the
  27 .\" Common Development and Distribution License (the "License").
  28 .\" You may not use this file except in compliance with the License.
  29 .\"
  30 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  31 .\" or http://www.opensolaris.org/os/licensing.
  32 .\" See the License for the specific language governing permissions
  33 .\" and limitations under the License.
  34 .\"
  35 .\" When distributing Covered Code, include this CDDL HEADER in each
  36 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  37 .\" If applicable, add the following below this CDDL HEADER, with the
  38 .\" fields enclosed by brackets "[]" replaced with your own identifying
  39 .\" information: Portions Copyright [yyyy] [name of copyright owner]
  40 .\"
  41 .\"
  42 .\" Copyright 1989 AT&T
  43 .\" Portions Copyright (c) 1992, X/Open Company Limited  All Rights Reserved
  44 .\" Copyright (c) 2006, Sun Microsystems, Inc.  All Rights Reserved.
  45 .\" Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
  46 .\"
  47 .Dd Feb 9, 2021
  48 .Dt CMP 1
  49 .Os
  50 .Sh NAME
  51 .Nm cmp
  52 .Nd compare two files
  53 .Sh SYNOPSIS
  54 .Nm
  55 .Op Fl bcdilns
  56 .Ar file1 file2
  57 .Op Ar skip1 Op Ar skip2
  58 .Sh DESCRIPTION
  59 The
  60 .Nm
  61 utility compares two files.
  62 .Nm
  63 writes no output if the files are the same.
  64 Under default options, if they differ, it writes to standard output the byte
  65 and line numbers at which the first difference occurred.
  66 Bytes and lines are numbered beginning with 1.
  67 .Ar skip1
  68 and
  69 .Ar skip2
  70 are initial byte offsets into
  71 .Ar file1
  72 and
  73 .Ar file2
  74 respectively, and are specified in bytes or can be given with a suffix of
  75 .Cm k
  76 for kilobytes or
  77 .Cm m
  78 for megabytes.
  79 .Lp
  80 If either
  81 .Ar file1
  82 or
  83 .Ar file2
  84 is a dash
  85 .Pq Ar \(mi ,
  86 .Nm
  87 uses standard input starting at the current location.
  88 .Sh OPTIONS
  89 The following options are supported:
  90 .Bl -tag -width Ar
  91 .It Fl b Ns \&, Fl \-print-bytes
  92 Print differing bytes as 3-digit octal values.
  93 .It Fl c Ns \&, Fl \-print-chars
  94 Print differing bytes as follows:
  95 .Bl -bullet -width Ds
  96 .It
  97 non-space printable characters as themselves;
  98 .It
  99 space and control characters as
 100 .Em ^
 101 followed by a letter of the alphabet;
 102 .It
 103 characters with the high bit set as the lower 7-bit character prefixed by
 104 .Em M^
 105 for 7-bit space and non-printable characters, and
 106 .Em M-
 107 for all other characters.
 108 If the 7-bit character encoding is not ASCII then the characters are converted
 109 to ASCII to determine whether the high bit is set and, if set, it is cleared
 110 and converted back to the native encoding.
 111 Multibyte characters in the current locale are treated as printable characters.
 112 .El
 113 .It Fl d Ar differences Ns \&, Fl \-differences Ns = Ns Ar differences
 114 Print at most
 115 .Ar differences
 116 differences using
 117 .Fl l
 118 .Pq Fl -verbose
 119 output format.
 120 If
 121 .Ar differences
 122 is
 123 .Cm 0
 124 then this is equivalent to passing the
 125 .Fl s
 126 or
 127 .Fl \-silent
 128 option.
 129 .It Fl i Ar skip1 Ns Op : Ns Ar skip2 Ns \&, Fl -skip Ns = Ns Ar skip1 Ns Op : Ns Ar skip2 Ns \&, Fl -ignore-initial Ns = Ns Ar skip1 Ns Op : Ns Ar skip2
 130 Skip the first
 131 .Ar skip1
 132 bytes in
 133 .Ar file1
 134 and the first
 135 .Ar skip2
 136 bytes in
 137 .Ar file2 .
 138 If
 139 .Ar skip2
 140 is omitted then
 141 .Ar skip1
 142 is used for that value.
 143 The default value is
 144 .Ar 0:0 .
 145 .It Fl l Ns \&, Fl \-verbose
 146 Write the byte number (decimal) and the differing bytes (octal) for each
 147 difference.
 148 .It Fl n Ar count Ns \&, Fl \-count Ns = Ns Ar count Ns \&, Fl \-bytes Ns = Ns Ar count
 149 Compare at most
 150 .Ar count
 151 bytes.
 152 .It Fl s Ns \&, Fl \-silent \&, Fl \-quiet
 153 Write nothing for differing files.
 154 Return exit status only.
 155 .El
 156 .Sh OPERANDS
 157 The following operands are supported:
 158 .Bl -tag -width Ar
 159 .It Ar file1
 160 A path name of the first file to be compared.
 161 If
 162 .Ar file1
 163 is
 164 .Ar \(mi ,
 165 the standard input is used.
 166 .It Ar file2
 167 A path name of the second file to be compared.
 168 If
 169 .Ar file2
 170 is
 171 .Ar \(mi ,
 172 the standard input is used.
 173 .It Ar skip1
 174 The number of initial bytes from
 175 .Ar file1
 176 to skip before beginning the comparison.
 177 .It Ar skip2
 178 The number of initial bytes from
 179 .Ar file2
 180 to skip before beginning the comparison.
 181 If
 182 .Ar skip1
 183 is specified but
 184 .Ar skip2
 185 is not, then the value of
 186 .Ar skip1
 187 is also implicitly used for
 188 .Ar skip2 .
 189 .El
 190 .Pp
 191 If both
 192 .Ar file1
 193 and
 194 .Ar file2
 195 refer to standard input or refer to the same FIFO, block or character special
 196 file, an error results.
 197 .Pp
 198 .Ar skip
 199 values are specified in bytes, or can be suffixed with
 200 .Cm k
 201 .Pq for kilobytes
 202 or
 203 .Cm m
 204 .Pq for megabytes.
 205 .Sh EXIT STATUS
 206 The following exit values are returned:
 207 .Bl -tag -width Ds
 208 .It Sy 0
 209 The files or portions compared are identical.
 210 .It Sy 1
 211 The files or portions compared are different.
 212 .It Sy >1
 213 An error ocurred.
 214 .El
 215 .Sh EXAMPLES
 216 .Bl -tag -width Ds
 217 .It Sy Example 1 No Comparing Files Byte for Byte
 218 The following example does a byte for byte comparison of
 219 .Ar file1
 220 and
 221 .Ar file2 ,
 222 skipping the first 1024 bytes in
 223 .Ar file2
 224 before starting the comparison.
 225 .Bd -literal
 226 $ cmp file1 file2 0 1024
 227 .Ed
 228 .El
 229 .Sh ENVIRONMENT VARIABLES
 230 See
 231 .Xr environ 5
 232 for descriptions of the following environment variables
 233 that affect the execution of
 234 .Nm :
 235 .Ev LANG ,
 236 .Ev LC_ALL ,
 237 .Ev LC_TYPE ,
 238 .Ev LC_MESSAGES ,
 239 .Ev LC_NUMERIC ,
 240 and
 241 .Ev NLSPATH .
 242 .Sh INTERFACE STABILITY
 243 The command line interface of
 244 .Nm
 245 is
 246 .Sy Committed .
 247 The output of
 248 .Nm
 249 is
 250 .Sy Standard .
 251 .Sh SEE ALSO
 252 .Xr comm 1 ,
 253 .Xr diff 1 ,
 254 .Xr attributes 5 ,
 255 .Xr environ 5 ,
 256 .Xr largefile 5 ,
 257 .Xr standards 5