xref: /netbsd-src/usr.bin/cmp/cmp.1 (revision 01869ca4d24a86379a68731bf9706a9f0820fe4e)
1.\"	$NetBSD: cmp.1,v 1.13 2017/07/03 21:34:18 wiz Exp $
2.\"
3.\" Copyright (c) 1987, 1990, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" the Institute of Electrical and Electronics Engineers, Inc.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. Neither the name of the University nor the names of its contributors
18.\"    may be used to endorse or promote products derived from this software
19.\"    without specific prior written permission.
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE.
32.\"
33.\"     @(#)cmp.1	8.1 (Berkeley) 6/6/93
34.\"
35.Dd December 13, 2016
36.Dt CMP 1
37.Os
38.Sh NAME
39.Nm cmp
40.Nd compare two files
41.Sh SYNOPSIS
42.Nm
43.Op Fl c
44.Op Fl l | Fl s
45.Ar file1 file2
46.Op Ar skip1 Op Ar skip2
47.Sh DESCRIPTION
48The cmp utility compares two files of any type and writes the results
49to the standard output.
50By default,
51.Nm
52is silent if the files are the same; if they differ, the byte
53and line number at which the first difference occurred is reported.
54.Pp
55Bytes and lines are numbered beginning with one.
56.Pp
57The following options are available:
58.Bl -tag -width flag
59.It Fl c
60Do the compare using
61.Xr getc 3
62rather than
63.Xr mmap 2 .
64Combined with the
65.Fl l
66flag, this can be helpful in locating an I/O error in the underlying
67device.
68.It Fl l
69Print the byte number (decimal) and the differing
70byte values (octal) for each difference.
71.It Fl s
72Print nothing for differing files; return exit
73status only.
74.El
75.Pp
76The optional arguments
77.Ar skip1
78and
79.Ar skip2
80are the byte offsets from the beginning of
81.Ar file1
82and
83.Ar file2 ,
84respectively, where the comparison will begin.
85The offset is decimal by default, but may be expressed as an hexadecimal
86or octal value by preceding it with a leading ``0x'' or ``0''.
87.Sh EXIT STATUS
88The
89.Nm
90utility exits with one of the following values:
91.Bl -tag -width 4n
92.It 0
93The files are identical.
94.It 1
95The files are different; this includes the case
96where one file is identical to the first part of
97the other.
98In the latter case, if the
99.Fl s
100option has not been specified,
101.Nm
102writes to standard output that EOF was reached in the shorter
103file (before any differences were found).
104.It >1
105An error occurred.
106.El
107.Sh SEE ALSO
108.Xr comm 1 ,
109.Xr diff 1 ,
110.Xr diff3 1 ,
111.Xr sdiff 1
112.Sh STANDARDS
113The
114.Nm
115utility is expected to be
116.St -p1003.2
117compatible.
118.Sh HISTORY
119The
120.Nm
121utility first appeared in
122.At v1 .
123