cmp (Unix)
In computing, cmp
is a command-line utility for computer systems that use Unix or a Unix-like operating system. It compares two files of any type and writes the results to the standard output. By default, cmp
is silent if the files are the same; if they differ, the byte and line number at which the first difference occurred is reported. The command is also available in the OS-9 shell.[1]
Original author(s) | Dennis Ritchie |
---|---|
Developer(s) | AT&T Bell Laboratories |
Initial release | November 3, 1971 |
Operating system | Unix, Unix-like, Plan 9, Inferno, OS-9 |
Type | Command |
License | coreutils: GPLv3+ |
History
cmp
is part of the X/Open Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and the Single Unix Specification.[2] It first appeared in Version 1 Unix.[3]
The version of cmp
bundled in GNU coreutils was written by Torbjorn Granlund and David MacKenzie.[4]
Switches
cmp
may be qualified by the use of command-line switches. The switches supported by the GNU version of cmp
are:
-b, --print-bytes
- Print the differing bytes. Display control bytes as a '
^
' followed by a letter of the alphabet and precede bytes that have the high bit set with 'M-
' (which stands for "meta"). -i SKIP, --ignore-initial=SKIP
- Skip the first SKIP bytes of input.
-i SKIP1:SKIP2, --ignore-initial=SKIP1:SKIP2
: Skip the first SKIP1 bytes of FILE1 and the first SKIP2 bytes of FILE2.-l, --verbose
- Output the (decimal) byte numbers and (octal) values of all differing bytes, instead of the default standard output. Also, output the EOF message if one file is shorter than the other.
-n LIMIT, --bytes=LIMIT
- Compare at most LIMIT bytes.
-s, --quiet, --silent
- Output nothing; yield exit status only.
-v, --version
- Output version info.
--help
- Outputs a help file.
Operands that are byte counts are normally decimal, but may be preceded by '0
' for octal and '0x
' for hexadecimal.
A byte count can be followed by a suffix to specify a multiple of that count; in this case an omitted integer is understood to be 1. A bare size letter, or one followed by 'iB
', specifies a multiple using powers of 1024. A size letter followed by 'B
' specifies powers of 1000 instead. For example, '-n 4M
' and '-n 4MiB
' are equivalent to '-n 4194304
', whereas '-n 4MB
' is equivalent to '-n 4000000
'. This notation is upward compatible with the SI prefixes[5] for decimal multiples and with the IEC 60027-2 prefixes for binary multiples.[6]
Return values
- 0 – files are identical
- 1 – files differ
- 2 – inaccessible or missing argument
References
- Paul S. Dayan (1992). The OS-9 Guru - 1 : The Facts. Galactic Industrial Limited. ISBN 0-9519228-0-7.
- – Commands & Utilities Reference, The Single UNIX Specification, Issue 7 from The Open Group
- – FreeBSD General Commands Manual
- https://linux.die.net/man/1/cmp
- http://www.bipm.fr/enus/3_SI/si-prefixes.html
- "Definitions of the SI units: The binary prefixes". physics.nist.gov. Retrieved 21 April 2018.
External links
![]() |
The Wikibook Guide to Unix has a page on the topic of: Commands |
- : compare two files – Commands & Utilities Reference, The Single UNIX Specification, Issue 7 from The Open Group
- – Plan 9 Programmer's Manual, Volume 1
- Comparing and Merging Files: Invoking cmp The section of the manual of GNU cmp in the diffutils free manual.