cmp.1 (2049B)
- .\" utils-std: Collection of commonly available Unix tools
- .\" Copyright 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- .\" SPDX-License-Identifier: MPL-2.0
- .Dd 2024-05-02
- .Dt CMP 1
- .Os
- .Sh NAME
- .Nm cmp
- .Nd compare two files
- .Sh SYNOPSIS
- .Nm
- .Op Fl ls
- .Op Fl n Ar max_bytes
- .Ar file1
- .Ar file2
- .Sh DESCRIPTION
- The
- .Nm
- utility checks files
- .Ar file1
- and
- .Ar file2
- for a different byte and prints it out.
- .Sh OPTIONS
- The following options are supported:
- .Bl -tag -width __
- .It Fl l
- Write the byte number and if found, the two bytes found different.
- .It Fl n Ar max_bytes
- Only compare the first
- .Ar max_bytes .
- .It Fl s
- Write nothing when files differ, errors are still printed out to stderr.
- .El
- .Sh STDOUT
- When a difference is found, the default message format is:
- .Bd -ragged -offset indent -compact
- .Dq %s %s differ: char %d, line %d\en ,
- .Ar file1 ,
- .Ar file2 ,
- .Aq Ar byte position within line
- .Aq Ar line position
- .Ed
- .Pp
- When
- .Fl l
- is passed, the format is:
- .Bd -ragged -offset indent -compact
- .Dq %d %o %o\en ,
- .Aq Ar byte position ,
- .Aq Ar file1 byte ,
- .Aq Ar file2 byte
- .Ed
- .Pp
- When
- .Fl s
- is passed, nothing should be printed to standard output.
- .Sh STDERR
- If
- .Fl s
- is not passed, and a file is shorter than the other,
- an error with the following format is printed:
- .Bd -ragged -offset indent
- .Dq cmp: EOF on %s line %ld\en ,
- .Aq Ar name of shorter file ,
- .Aq Ar line number
- .Ed
- .Pp
- Note that unlike the other formats, only the following format is standard:
- .Bd -ragged -offset indent -compact
- .Dq cmp: EOF on %s%s\en ,
- .Aq Ar name of shorter file ,
- .Aq Ar additional info
- .Ed
- Where
- .Aq Ar additional info
- can be empty or have any single-line information starting with a space.
- .Sh EXIT STATUS
- .Bl -tag -width __
- .It 0
- The files are identical.
- .It 1
- The files are different.
- .It >1
- An error occurred.
- .El
- .Sh STANDARDS
- .Nm
- should be compliant with the
- IEEE Std 1003.1-2024 (“POSIX.1”)
- specification.
- The
- .Fl n Ar max_bytes
- option is an extension.
- .Sh AUTHORS
- .An Haelwenn (lanodan) Monnier Aq Mt contact+utils@hacktivis.me