In
computing
Computing is any goal-oriented activity requiring, benefiting from, or creating computer, computing machinery. It includes the study and experimentation of algorithmic processes, and the development of both computer hardware, hardware and softw ...
,
cmp
is a
command-line utility on
Unix
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
and
Unix-like
A Unix-like (sometimes referred to as UN*X, *nix or *NIX) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Uni ...
operating system
An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ...
s that compares two
files of any type and writes the results to the
standard output Standard may refer to:
Symbols
* Colours, standards and guidons, kinds of military signs
* Standard (emblem), a type of a large symbol or emblem used for identification
Norms, conventions or requirements
* Standard (metrology), an object t ...
. By default,
cmp
is silent if the files are the same; if they differ, the
byte
The byte is a unit of digital information that most commonly consists of eight bits. Historically, the byte was the number of bits used to encode a single character of text in a computer and for this reason it is the smallest addressable un ...
and line number at which the first difference occurred is reported. The command is also available in the
OS-9
OS-9 is a family of real-time, process-based, multitasking, multi-user operating systems, developed in the 1980s, originally by Microware Systems Corporation for the Motorola 6809 microprocessor. It was purchased by Radisys Corp in 2001, a ...
shell.
History
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
The Single UNIX Specification (SUS) is a standard for computer operating systems, compliance with which is required to qualify for using the "UNIX" trademark. The standard specifies programming interfaces for the C language, a command-line shell, ...
. It first appeared in
Version 1 Unix.
The version of
cmp
bundled in
GNU coreutils
The GNU Core Utilities or coreutils is a collection of GNU software that implements many standard, Unix-based shell commands. The utilities generally provide POSIX compliant interface when the environment variable is set, but otherwise offers ...
was written by Torbjorn Granlund and David MacKenzie.
The command is available as a separate package for Microsoft Windows as part of the
UnxUtils
UnxUtils is a collection of utility programs that provide popular Unix-based shell commands ported from GNU implementations as native Windows programs that depend only on Win32 and the Microsoft C- runtime ( msvcrt.dll). The collection wa ...
collection of
native Win32 ports Ports collections (or ports trees, or just ports) are the sets of makefiles and Patch (Unix), patches provided by the BSD-based operating systems, FreeBSD, NetBSD, and OpenBSD, as a simple method of installing software or creating binary packages. T ...
of common GNU Unix-like utilities. The command has also been ported to the
IBM i
IBM i (the ''i'' standing for ''integrated'') is an operating system developed by IBM for IBM Power Systems. It was originally released in 1988 as OS/400, as the sole operating system of the IBM AS/400 line of systems. It was renamed to i5/OS in 2 ...
operating system.
Switches
may be qualified by the use of
command-line switches. The switches supported by notable implementations of are:
Operands that are byte counts are normally decimal, but may be preceded by '' for octal and '' 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 '', specifies a multiple using powers of 1024. A size letter followed by '' specifies powers of 1000 instead. For example, '' and '' are equivalent to '', whereas '' is equivalent to ''. This notation is upward compatible with the SI prefixes for decimal multiples and with the IEC 60027-2 prefixes for binary multiples.
Example
Return values
* 0 – files are identical
* 1 – files differ
* 2 – inaccessible or missing argument
See also
*
Comparison of file comparison tools
*
List of Unix commands
This is a list of the shell commands of the most recent version of the Portable Operating System Interface (POSIX) IEEE Std 1003.1-2024 which is part of the Single UNIX Specification (SUS). These commands are implemented in many shells on moder ...
References
External links
*
''Comparing and Merging Files'': Invoking cmpThe section of the manual of GNU cmp in the
diffutils free manual.
{{Plan 9 commands
Free file comparison tools
Standard Unix programs
Unix SUS2008 utilities
Plan 9 commands
Inferno (operating system) commands
IBM i Qshell commands