xref: /freebsd/usr.bin/cmp/cmp.1 (revision bdcbfde31e8e9b343f113a1956384bdf30d1ed62)
19b50d902SRodney W. Grimes.\" Copyright (c) 1987, 1990, 1993
29b50d902SRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
39b50d902SRodney W. Grimes.\"
49b50d902SRodney W. Grimes.\" This code is derived from software contributed to Berkeley by
59b50d902SRodney W. Grimes.\" the Institute of Electrical and Electronics Engineers, Inc.
69b50d902SRodney W. Grimes.\"
79b50d902SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
89b50d902SRodney W. Grimes.\" modification, are permitted provided that the following conditions
99b50d902SRodney W. Grimes.\" are met:
109b50d902SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
119b50d902SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
129b50d902SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
139b50d902SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
149b50d902SRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
15fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors
169b50d902SRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
179b50d902SRodney W. Grimes.\"    without specific prior written permission.
189b50d902SRodney W. Grimes.\"
199b50d902SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
209b50d902SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
219b50d902SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
229b50d902SRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
239b50d902SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
249b50d902SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
259b50d902SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
269b50d902SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
279b50d902SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
289b50d902SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
299b50d902SRodney W. Grimes.\" SUCH DAMAGE.
309b50d902SRodney W. Grimes.\"
31f6787614SKyle Evans.Dd September 23, 2021
329b50d902SRodney W. Grimes.Dt CMP 1
339b50d902SRodney W. Grimes.Os
349b50d902SRodney W. Grimes.Sh NAME
359b50d902SRodney W. Grimes.Nm cmp
369b50d902SRodney W. Grimes.Nd compare two files
379b50d902SRodney W. Grimes.Sh SYNOPSIS
388fe908efSRuslan Ermilov.Nm
39fe0e3643SRuslan Ermilov.Op Fl l | s | x
40*f66b9b40SKyle Evans.Op Fl bhz
418d546b68SKyle Evans.Op Fl -ignore-initial Ns Cm = Ns Ar num1 Ns Op :num2
424e380e84SKyle Evans.Op Fl -bytes Ns Cm = Ns Ar num
439b50d902SRodney W. Grimes.Ar file1 file2
449b50d902SRodney W. Grimes.Op Ar skip1 Op Ar skip2
459b50d902SRodney W. Grimes.Sh DESCRIPTION
46f771f052SPhilippe CharnierThe
478fe908efSRuslan Ermilov.Nm
48f771f052SPhilippe Charnierutility compares two files of any type and writes the results
499b50d902SRodney W. Grimesto the standard output.
509b50d902SRodney W. GrimesBy default,
518fe908efSRuslan Ermilov.Nm
529b50d902SRodney W. Grimesis silent if the files are the same; if they differ, the byte
539b50d902SRodney W. Grimesand line number at which the first difference occurred is reported.
549b50d902SRodney W. Grimes.Pp
559b50d902SRodney W. GrimesBytes and lines are numbered beginning with one.
569b50d902SRodney W. Grimes.Pp
579b50d902SRodney W. GrimesThe following options are available:
58fe0e3643SRuslan Ermilov.Bl -tag -width indent
59*f66b9b40SKyle Evans.It Fl b , Fl -print-bytes
60*f66b9b40SKyle EvansPrint each byte when a difference is found.
61e1bfde1bSBrian Somers.It Fl h
624e9e907dSRuslan ErmilovDo not follow symbolic links.
638d546b68SKyle Evans.It Fl i Ar num1 Ns Oo :num2 Oc , Fl -ignore-initial= Ns Ar num1 Ns Op :num2
648d546b68SKyle EvansSkip
658d546b68SKyle Evans.Ar num1
668d546b68SKyle Evansbytes from
678d546b68SKyle Evans.Ar file1 ,
688d546b68SKyle Evansand optionally skip
698d546b68SKyle Evans.Ar num2
708d546b68SKyle Evansbytes from
718d546b68SKyle Evans.Ar file2 .
728d546b68SKyle EvansIf
738d546b68SKyle Evans.Ar num2
748d546b68SKyle Evansis not specified, then
758d546b68SKyle Evans.Ar num1
768d546b68SKyle Evansis applied for both
778d546b68SKyle Evans.Ar file1
788d546b68SKyle Evansand
798d546b68SKyle Evans.Ar file2 .
808facfdcfSKyle Evans.It Fl l , Fl -verbose
819b50d902SRodney W. GrimesPrint the byte number (decimal) and the differing
829b50d902SRodney W. Grimesbyte values (octal) for each difference.
834e380e84SKyle Evans.It Fl n Ar num , Fl -bytes= Ns num
844e380e84SKyle EvansOnly compare up to
854e380e84SKyle Evans.Ar num
864e380e84SKyle Evansbytes.
878facfdcfSKyle Evans.It Fl s , Fl -silent , Fl -quiet
889b50d902SRodney W. GrimesPrint nothing for differing files; return exit
899b50d902SRodney W. Grimesstatus only.
90e03983a3SPoul-Henning Kamp.It Fl x
91e03983a3SPoul-Henning KampLike
92e03983a3SPoul-Henning Kamp.Fl l
93e03983a3SPoul-Henning Kampbut prints in hexadecimal and using zero as index
94e03983a3SPoul-Henning Kampfor the first byte in the files.
953e6902efSBrian Somers.It Fl z
963e6902efSBrian SomersFor regular files compare file sizes first, and fail the comparison if they
973e6902efSBrian Somersare not equal.
989b50d902SRodney W. Grimes.El
999b50d902SRodney W. Grimes.Pp
1009b50d902SRodney W. GrimesThe optional arguments
1019b50d902SRodney W. Grimes.Ar skip1
1029b50d902SRodney W. Grimesand
1039b50d902SRodney W. Grimes.Ar skip2
1049b50d902SRodney W. Grimesare the byte offsets from the beginning of
1059b50d902SRodney W. Grimes.Ar file1
1069b50d902SRodney W. Grimesand
1079b50d902SRodney W. Grimes.Ar file2 ,
1089b50d902SRodney W. Grimesrespectively, where the comparison will begin.
109d64ada50SJens SchweikhardtThe offset is decimal by default, but may be expressed as a hexadecimal
1109b50d902SRodney W. Grimesor octal value by preceding it with a leading ``0x'' or ``0''.
111f6787614SKyle Evans.Pp
112f6787614SKyle Evans.Ar skip1
113f6787614SKyle Evansand
114f6787614SKyle Evans.Ar skip2
115f6787614SKyle Evansmay also be specified with SI size suffixes.
116fe0e3643SRuslan Ermilov.Sh EXIT STATUS
1179b50d902SRodney W. GrimesThe
1188fe908efSRuslan Ermilov.Nm
1199b50d902SRodney W. Grimesutility exits with one of the following values:
1209b50d902SRodney W. Grimes.Bl -tag -width 4n
1219b50d902SRodney W. Grimes.It 0
1229b50d902SRodney W. GrimesThe files are identical.
1239b50d902SRodney W. Grimes.It 1
1249b50d902SRodney W. GrimesThe files are different; this includes the case
1259b50d902SRodney W. Grimeswhere one file is identical to the first part of
1269b50d902SRodney W. Grimesthe other.
1279b50d902SRodney W. GrimesIn the latter case, if the
1289b50d902SRodney W. Grimes.Fl s
1299b50d902SRodney W. Grimesoption has not been specified,
1308fe908efSRuslan Ermilov.Nm
131423bac3eSSteve Pricewrites to standard error that EOF was reached in the shorter
1329b50d902SRodney W. Grimesfile (before any differences were found).
1339b50d902SRodney W. Grimes.It >1
1349b50d902SRodney W. GrimesAn error occurred.
1359b50d902SRodney W. Grimes.El
136022ebaf5SFernando Apesteguía.Sh EXAMPLES
13718319935SFernando ApesteguíaAssuming a file named
13818319935SFernando Apesteguía.Pa example.txt
13918319935SFernando Apesteguíawith the following contents:
140022ebaf5SFernando Apesteguía.Bd -literal -offset indent
141022ebaf5SFernando Apesteguíaa
142022ebaf5SFernando Apesteguíab
143022ebaf5SFernando Apesteguíac
144022ebaf5SFernando Apesteguía.Ed
145022ebaf5SFernando Apesteguía.Pp
14618319935SFernando ApesteguíaCompare stdin with
14718319935SFernando Apesteguía.Pa example.txt :
148022ebaf5SFernando Apesteguía.Bd -literal -offset indent
149022ebaf5SFernando Apesteguía$ echo -e "a\\nb\\nc" | cmp - example.txt
150022ebaf5SFernando Apesteguía.Ed
151022ebaf5SFernando Apesteguía.Pp
15218319935SFernando ApesteguíaSame as above but introducing a change in the third byte of stdin.
153022ebaf5SFernando ApesteguíaShow the byte number (decimal) and differing byte (octal):
154022ebaf5SFernando Apesteguía.Bd -literal -offset indent
155022ebaf5SFernando Apesteguía$ echo -e "a\\nR\\nc" | cmp -l - example.txt
156022ebaf5SFernando Apesteguía     3 122 142
157022ebaf5SFernando Apesteguía.Ed
158022ebaf5SFernando Apesteguía.Pp
15918319935SFernando ApesteguíaCompare file sizes of
16018319935SFernando Apesteguía.Pa example.txt
16118319935SFernando Apesteguíaand
16218319935SFernando Apesteguía.Pa /boot/loader.conf
16318319935SFernando Apesteguíaand return 1 if they are not equal.
164022ebaf5SFernando ApesteguíaNote that
165022ebaf5SFernando Apesteguía.Fl z
166022ebaf5SFernando Apesteguíacan only be used with regular files:
167022ebaf5SFernando Apesteguía.Bd -literal -offset indent
168022ebaf5SFernando Apesteguía$ cmp -z example.txt /boot/loader.conf
169022ebaf5SFernando Apesteguíaexample.txt /boot/loader.conf differ: size
170022ebaf5SFernando Apesteguía.Ed
171022ebaf5SFernando Apesteguía.Pp
17218319935SFernando ApesteguíaCompare stdin with
17318319935SFernando Apesteguía.Pa example.txt
17418319935SFernando Apesteguíaomitting the first 4 bytes from stdin and the first 2 bytes from
17518319935SFernando Apesteguía.Pa example.txt :
176022ebaf5SFernando Apesteguía.Bd -literal -offset indent
177022ebaf5SFernando Apesteguía$ echo -e "a\\nR\\nb\\nc" | cmp - example.txt 4 2
178022ebaf5SFernando Apesteguía.Ed
1799b50d902SRodney W. Grimes.Sh SEE ALSO
1809b50d902SRodney W. Grimes.Xr diff 1 ,
1819b50d902SRodney W. Grimes.Xr diff3 1
1829b50d902SRodney W. Grimes.Sh STANDARDS
1839b50d902SRodney W. GrimesThe
1848fe908efSRuslan Ermilov.Nm
1859b50d902SRodney W. Grimesutility is expected to be
1869b50d902SRodney W. Grimes.St -p1003.2
1879b50d902SRodney W. Grimescompatible.
188c4dfa475SEitan AdlerThe
189*f66b9b40SKyle Evans.Fl b ,
190c4dfa475SEitan Adler.Fl h ,
1918d546b68SKyle Evans.Fl i ,
1924e380e84SKyle Evans.Fl n ,
193c4dfa475SEitan Adler.Fl x ,
194c4dfa475SEitan Adlerand
195c4dfa475SEitan Adler.Fl z
196c4dfa475SEitan Adleroptions are extensions to the standard.
197f6787614SKyle Evans.Ar skip1
198f6787614SKyle Evansand
199f6787614SKyle Evans.Ar skip2
200f6787614SKyle Evansarguments are extensions to the standard.
201b8923d4cSWolfram Schneider.Sh HISTORY
202b8923d4cSWolfram SchneiderA
2038fe908efSRuslan Ermilov.Nm
204b8923d4cSWolfram Schneidercommand appeared in
205b8923d4cSWolfram Schneider.At v1 .
206f6787614SKyle Evans.Sh BUGS
207f6787614SKyle EvansThe phrase
208f6787614SKyle Evans.Dq SI size suffixes
209f6787614SKyle Evansabove refers to the traditional power of two convention, as described in
210f6787614SKyle Evans.Xr expand_number 3 .
211