Template:Short description Template:Lowercase title {{#invoke:Infobox|infobox}}Template:Template other{{#invoke:Check for unknown parameters | check | showblankpositional=1 | unknown = Template:Main other | preview = Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y | AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo upright | logo size | logo title | logo_alt | logo_caption | logo_upright | logo_size | logo_title | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot upright | screenshot size | screenshot title | screenshot_alt | screenshot_upright | screenshot_size | screenshot_title | service_name | size | standard | title | ver layout | website | qid }}Template:Main other In computing, cmp is a command-line utility on Unix and Unix-like operating systems that 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.<ref>Template:Cite book</ref>

HistoryEdit

<syntaxhighlight lang="text" class="" style="" inline="1">cmp</syntaxhighlight> 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>Template:Man</ref> It first appeared in Version 1 Unix.<ref>Template:Man</ref> The version of cmp bundled in GNU coreutils was written by Torbjorn Granlund and David MacKenzie.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> The command is available as a separate package for Microsoft Windows as part of the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> The Template:Mono command has also been ported to the IBM i operating system.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

SwitchesEdit

Template:Mono may be qualified by the use of command-line switches. The switches supported by notable implementations of Template:Mono are:

Name Description Unix Plan 9 Inferno FreeBSD Linux Template:Nowrap
Template:Mono Print the differing bytes. Display control bytes as a 'Template:Mono' followed by a letter of the alphabet and precede bytes that have the high bit set with 'Template:Mono' (which stands for "meta"). Template:No Template:No Template:No Template:No Template:Yes Template:No
Template:Mono Do not follow symbolic links. Template:No Template:No Template:No Template:Yes Template:No Template:No
Template:Mono Skip the first SKIP bytes of input. Template:No Template:No Template:No Template:No Template:Yes Template:No
Template:Mono Skip the first SKIP1 bytes of FILE1 and the first SKIP2 bytes of FILE2. Template:No Template:No Template:No Template:No Template:Yes Template:No
Template:Mono 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.

Template:Yes Template:Yes Template:Yes Template:Yes Template:Yes Template:Yes
Template:Mono Print the line number of the first differing byte. Template:Yes Template:Yes Template:Yes Template:No Template:No Template:No
Template:Mono Compare at most LIMIT bytes. Template:No Template:No Template:No Template:No Template:Yes Template:No
Template:Mono Output nothing; yield exit status only. Template:Yes Template:Yes Template:Yes Template:Yes Template:Yes Template:Yes
Template:Mono Text mode where the files are opened in text mode and translated to the CCSID of the job before comparing byte for byte. Template:No Template:No Template:No Template:No Template:No Template:Yes
Template:Mono Output version info. Template:No Template:No Template:No Template:No Template:Yes Template:No
Template:Mono Like -l but prints in hexadecimal and using zero as index for the first byte in the files. Template:No Template:No Template:No Template:Yes Template:No Template:No
Template:Mono For regular files compare file sizes first, and fail the comparison if they are not equal. Template:No Template:No Template:No Template:Yes Template:No Template:No
Template:Mono Outputs a help file. Template:No Template:No Template:No Template:No Template:Yes Template:No

Operands that are byte counts are normally decimal, but may be preceded by 'Template:Mono' for octal and 'Template:Mono' 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 'Template:Mono', specifies a multiple using powers of 1024. A size letter followed by 'Template:Mono' specifies powers of 1000 instead. For example, 'Template:Mono' and 'Template:Mono' are equivalent to 'Template:Mono', whereas 'Template:Mono' is equivalent to 'Template:Mono'. This notation is upward compatible with the SI prefixes<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> for decimal multiples and with the IEC 60027-2 prefixes for binary multiples.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

ExampleEdit

File:Cmp-example-command-gimp.gif
Example usage of <syntaxhighlight lang="text" class="" style="" inline="1">cmp</syntaxhighlight> to find different bytes between 2 txt files

Return valuesEdit

  • 0 – files are identical
  • 1 – files differ
  • 2 – inaccessible or missing argument

See alsoEdit

ReferencesEdit

Template:Reflist

External linksEdit

Template:Sister project

Template:Unix commands Template:Plan 9 commands