1 .\"
   2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
   3 .\" permission to reproduce portions of its copyrighted documentation.
   4 .\" Original documentation from The Open Group can be obtained online at
   5 .\" http://www.opengroup.org/bookstore/.
   6 .\"
   7 .\" The Institute of Electrical and Electronics Engineers and The Open
   8 .\" Group, have given us permission to reprint portions of their
   9 .\" documentation.
  10 .\"
  11 .\" In the following statement, the phrase ``this text'' refers to portions
  12 .\" of the system documentation.
  13 .\"
  14 .\" Portions of this text are reprinted and reproduced in electronic form
  15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
  16 .\" Standard for Information Technology -- Portable Operating System
  17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
  18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
  19 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
  20 .\" between these versions and the original IEEE and The Open Group
  21 .\" Standard, the original IEEE and The Open Group Standard is the referee
  22 .\" document.  The original Standard can be obtained online at
  23 .\" http://www.opengroup.org/unix/online.html.
  24 .\"
  25 .\" This notice shall appear on any product containing this material.
  26 .\"
  27 .\" The contents of this file are subject to the terms of the
  28 .\" Common Development and Distribution License (the "License").
  29 .\" You may not use this file except in compliance with the License.
  30 .\"
  31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  32 .\" or http://www.opensolaris.org/os/licensing.
  33 .\" See the License for the specific language governing permissions
  34 .\" and limitations under the License.
  35 .\"
  36 .\" When distributing Covered Code, include this CDDL HEADER in each
  37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  38 .\" If applicable, add the following below this CDDL HEADER, with the
  39 .\" fields enclosed by brackets "[]" replaced with your own identifying
  40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
  41 .\"
  42 .\"
  43 .\" Copyright 1989 AT&T
  44 .\" Portions Copyright (c) 1992, X/Open Company Limited  All Rights Reserved
  45 .\" Copyright (c) 2006, Sun Microsystems, Inc.  All Rights Reserved.
  46 .\"
  47 .TH CMP 1 "Jul 19, 2006"
  48 .SH NAME
  49 cmp \- compare two files
  50 .SH SYNOPSIS
  51 .LP
  52 .nf
  53 \fBcmp\fR [\fB-l\fR | \fB-s\fR] \fIfile1\fR \fIfile2\fR [\fIskip1\fR] [\fIskip2\fR]
  54 .fi
  55 
  56 .SH DESCRIPTION
  57 .sp
  58 .LP
  59 The \fBcmp\fR utility compares two files. \fBcmp\fR writes no output if the
  60 files are the same. Under default options, if they differ, it writes to
  61 standard output the byte and line numbers at which the first difference
  62 occurred. Bytes and lines are numbered beginning with 1. If one file is an
  63 initial subsequence of the other, that fact is noted. \fIskip1\fR and
  64 \fIskip2\fR are initial byte offsets into \fIfile1\fR and \fIfile2\fR
  65 respectively, and can be either octal or decimal. A leading 0 denotes octal.
  66 .SH OPTIONS
  67 .sp
  68 .LP
  69 The following options are supported:
  70 .sp
  71 .ne 2
  72 .na
  73 \fB\fB-l\fR\fR
  74 .ad
  75 .RS 6n
  76 Write the byte number (decimal) and the differing bytes (octal) for each
  77 difference.
  78 .RE
  79 
  80 .sp
  81 .ne 2
  82 .na
  83 \fB\fB-s\fR\fR
  84 .ad
  85 .RS 6n
  86 Write nothing for differing files. Return exit status only.
  87 .RE
  88 
  89 .SH OPERANDS
  90 .sp
  91 .LP
  92 The following operands are supported:
  93 .sp
  94 .ne 2
  95 .na
  96 \fB\fIfile1\fR\fR
  97 .ad
  98 .RS 9n
  99 A path name of the first file to be compared. If \fIfile1\fR is \fB\(mi\fR, the
 100 standard input is used.
 101 .RE
 102 
 103 .sp
 104 .ne 2
 105 .na
 106 \fB\fIfile2\fR\fR
 107 .ad
 108 .RS 9n
 109 A path name of the second file to be compared. If \fIfile2\fR is \fB\(mi\fR,
 110 the standard input is used.
 111 .RE
 112 
 113 .sp
 114 .LP
 115 If both \fIfile1\fR and \fIfile2\fR refer to standard input or refer to the
 116 same \fBFIFO\fR special, block special or character special file, an error
 117 results.
 118 .SH USAGE
 119 .sp
 120 .LP
 121 See \fBlargefile\fR(5) for the description of the behavior of \fBcmp\fR when
 122 encountering files greater than or equal to 2 Gbyte (2^31 bytes).
 123 .SH EXAMPLES
 124 .LP
 125 \fBExample 1 \fRComparing Files Byte for Byte
 126 .sp
 127 .LP
 128 The following example does a byte for byte comparison of \fIfile1\fR and
 129 \fIfile2\fR:
 130 
 131 .sp
 132 .in +2
 133 .nf
 134 example% \fBcmp file1 file2 0 1024\fR
 135 .fi
 136 .in -2
 137 .sp
 138 
 139 .sp
 140 .LP
 141 It skips the first 1024 bytes in \fIfile2\fR before starting the comparison.
 142 
 143 .SH ENVIRONMENT VARIABLES
 144 .sp
 145 .LP
 146 See \fBenviron\fR(5) for descriptions of the following environment variables
 147 that affect the execution of \fBcmp\fR: \fBLANG\fR, \fBLC_ALL\fR,
 148 \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
 149 .SH EXIT STATUS
 150 .sp
 151 .LP
 152 The following error values are returned:
 153 .sp
 154 .ne 2
 155 .na
 156 \fB\fB0\fR\fR
 157 .ad
 158 .RS 6n
 159 The files are identical.
 160 .RE
 161 
 162 .sp
 163 .ne 2
 164 .na
 165 \fB\fB1\fR\fR
 166 .ad
 167 .RS 6n
 168 The files are different. This includes the case where one file is identical to
 169 the first part of the other.
 170 .RE
 171 
 172 .sp
 173 .ne 2
 174 .na
 175 \fB\fB>1\fR\fR
 176 .ad
 177 .RS 6n
 178 An error occurred.
 179 .RE
 180 
 181 .SH ATTRIBUTES
 182 .sp
 183 .LP
 184 See \fBattributes\fR(5) for descriptions of the following attributes:
 185 .sp
 186 
 187 .sp
 188 .TS
 189 box;
 190 c | c
 191 l | l .
 192 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 193 _
 194 CSI     Enabled
 195 _
 196 Interface Stability     Standard
 197 .TE
 198 
 199 .SH SEE ALSO
 200 .sp
 201 .LP
 202 \fBcomm\fR(1), \fBdiff\fR(1), \fBattributes\fR(5), \fBenviron\fR(5),
 203 \fBlargefile\fR(5), \fBstandards\fR(5)