Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Cmp (Unix)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Computer file comparison utility}} {{lowercase title}} {{Infobox software | name = cmp | logo = | author = [[Dennis Ritchie]]<br />([[AT&T Bell Laboratories]]) | developer = Various [[open-source software|open-source]] and [[commercial software|commercial]] developers | released = {{Start date and age|1971|11|3}} | latest release version = | latest release date = | programming language = Plan 9: [[C (programming language)|C]] | operating system = [[Unix]], [[Unix-like]], [[Plan 9 from Bell Labs|Plan 9]], [[Inferno (operating system)|Inferno]], [[OS-9]], [[IBM i]] | genre = [[Command (computing)|Command]] | license = [[coreutils]]: [[GPLv3+]]<br />Plan 9: [[MIT License]] | website = }} In [[computing]], '''<code>cmp</code>''' is a [[command-line interface|command-line]] utility on [[Unix]] and [[Unix-like]] [[operating system]]s that compares two [[Computer file|files]] of any type and writes the results to the [[standard output]]. By default, <code>cmp</code> 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.<ref>{{cite book|author=Paul S. Dayan|year=1992|title=The OS-9 Guru - 1 : The Facts|publisher=Galactic Industrial Limited|isbn=0-9519228-0-7}}</ref> ==History== {{code|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]].<ref>{{man|cu|printf|SUS}}</ref> It first appeared in [[Ancient Unix|Version 1 Unix]].<ref>{{man|1|cmp|FreeBSD}}</ref> The version of <code>cmp</code> bundled in [[GNU]] [[coreutils]] was written by Torbjorn Granlund and David MacKenzie.<ref>{{Cite web|url=https://linux.die.net/man/1/cmp|title=cmp(1): compare two files byte by byte - Linux man page|website=linux.die.net}}</ref> The command is available as a separate package for Microsoft Windows as part of the [[UnxUtils]] collection of [[Native (computing)|native]] [[Windows API|Win32]] [[porting|ports]] of common GNU Unix-like utilities.<ref>{{Cite web|url=http://unxutils.sourceforge.net/|title=Native Win32 ports of some GNU utilities|website=unxutils.sourceforge.net}}</ref> The {{Mono|cmp}} command has also been ported to the [[IBM i]] operating system.<ref>{{cite web |title=IBM System i Version 7.2 Programming Qshell |language=en |author=IBM |website=[[IBM]] |author-link=IBM |url=https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc |access-date=2020-09-05 }}</ref> ==Switches== {{mono|cmp}} may be qualified by the use of [[Command-line argument|command-line switches]]. The switches supported by notable implementations of {{mono|cmp}} are: {| class="wikitable" border="6" ! Name ! Description ! [[Unix]] ! [[Plan 9 from Bell Labs|Plan 9]] ! [[Inferno (operating system)|Inferno]] ! [[FreeBSD]] ! [[Linux]] ! {{nowrap|[[IBM i]]}} |- | {{mono|-b,<br />--print-bytes}} | Print the differing bytes. Display control bytes as a '{{mono|^}}' followed by a letter of the alphabet and precede bytes that have the high bit set with '{{mono|M-}}' (which stands for "[[Meta_key|meta]]"). | {{No}} | {{No}} | {{No}} | {{No}} | {{Yes}} | {{No}} |- | {{mono|-h}} | Do not follow symbolic links. | {{No}} | {{No}} | {{No}} | {{Yes}} | {{No}} | {{No}} |- | {{mono|1=-i SKIP,<br />--ignore-initial=SKIP}} | Skip the first SKIP bytes of input. | {{No}} | {{No}} | {{No}} | {{No}} | {{Yes}} | {{No}} |- | {{mono|1=-i SKIP1:SKIP2,<br />--ignore-initial=SKIP1:SKIP2}} | Skip the first SKIP1 bytes of FILE1 and the first SKIP2 bytes of FILE2. | {{No}} | {{No}} | {{No}} | {{No}} | {{Yes}} | {{No}} |- | {{mono|-l,<br />--verbose}} | Output the (decimal) byte numbers and (octal) values of all differing bytes, instead of the default standard output.<br> Also, output the EOF message if one file is shorter than the other. | {{Yes}} | {{Yes}} | {{Yes}} | {{Yes}} | {{Yes}} | {{Yes}} |- | {{mono|-L}} | Print the line number of the first differing byte. | {{Yes}} | {{Yes}} | {{Yes}} | {{No}} | {{No}} | {{No}} |- | {{mono|1=-n LIMIT,<br />--bytes=LIMIT}} | Compare at most LIMIT bytes. | {{No}} | {{No}} | {{No}} | {{No}} | {{Yes}} | {{No}} |- | {{mono|-s,<br />--quiet,<br />--silent}} | Output nothing; yield exit status only. | {{Yes}} | {{Yes}} | {{Yes}} | {{Yes}} | {{Yes}} | {{Yes}} |- | {{mono|-t}} | Text mode where the files are opened in text mode and translated to the [[CCSID]] of the job before comparing byte for byte. | {{No}} | {{No}} | {{No}} | {{No}} | {{No}} | {{Yes}} |- | {{mono|-v,<br />--version}} | Output version info. | {{No}} | {{No}} | {{No}} | {{No}} | {{Yes}} | {{No}} |- | {{mono|-x}} | Like -l but prints in hexadecimal and using zero as index for the first byte in the files. | {{No}} | {{No}} | {{No}} | {{Yes}} | {{No}} | {{No}} |- | {{mono|-z}} | For regular files compare file sizes first, and fail the comparison if they are not equal. | {{No}} | {{No}} | {{No}} | {{Yes}} | {{No}} | {{No}} |- | {{mono|--help}} | Outputs a help file. | {{No}} | {{No}} | {{No}} | {{No}} | {{Yes}} | {{No}} |} Operands that are byte counts are normally decimal, but may be preceded by '{{mono|0}}' for octal and '{{mono|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 '{{mono|iB}}', specifies a multiple using powers of 1024. A size letter followed by '{{mono|B}}' specifies powers of 1000 instead. For example, '{{mono|-n 4M}}' and '{{mono|-n 4MiB}}' are equivalent to '{{mono|-n 4194304}}', whereas '{{mono|-n 4MB}}' is equivalent to '{{mono|-n 4000000}}'. This notation is upward compatible with the SI prefixes<ref>{{cite web| url = http://www.bipm.fr/enus/3_SI/si-prefixes.html |title = Welcome - BIPM}}</ref> for decimal multiples and with the IEC 60027-2 prefixes for binary multiples.<ref>{{cite web|url=https://physics.nist.gov/cuu/Units/binary.html|title=Definitions of the SI units: The binary prefixes|website=physics.nist.gov|access-date=21 April 2018}}</ref> ==Example== [[File:Cmp-example-command-gimp.gif|thumb|520px|none|Example usage of {{code|cmp}} to find different bytes between 2 txt files]] ==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]] ==References== {{Reflist}} ==External links== {{Wikibooks|Guide to Unix|Commands}} * {{man|cu|cmp|SUS|compare two files}} * [https://www.gnu.org/software/diffutils/manual/html_node/Invoking-cmp.html ''Comparing and Merging Files'': Invoking cmp] The section of the manual of GNU cmp in the [[diffutils]] [[free manual]]. {{Unix commands}} {{Plan 9 commands}} [[Category:Free file comparison tools]] [[Category:Standard Unix programs]] [[Category:Unix SUS2008 utilities]] [[Category:Plan 9 commands]] [[Category:Inferno (operating system) commands]] [[Category:IBM i Qshell commands]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite book
(
edit
)
Template:Cite web
(
edit
)
Template:Code
(
edit
)
Template:Infobox
(
edit
)
Template:Infobox software
(
edit
)
Template:Lowercase title
(
edit
)
Template:Main other
(
edit
)
Template:Man
(
edit
)
Template:Mono
(
edit
)
Template:No
(
edit
)
Template:Nowrap
(
edit
)
Template:Plan 9 commands
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Sister project
(
edit
)
Template:Template other
(
edit
)
Template:Unix commands
(
edit
)
Template:Wikibooks
(
edit
)
Template:Yes
(
edit
)