Cmp (Unix)

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

Template:Short description Template:Lowercase title Script error: No such module "Infobox".Template:Template otherScript error: No such module "Check for unknown parameters".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.[1]

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] 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.[5] The Template:Mono command has also been ported to the IBM i operating system.[6]

Switches

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 IBM i
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"). No No No No Yes No
Template:Mono Do not follow symbolic links. No No No Yes No No
Template:Mono Skip the first SKIP bytes of input. No No No No Yes No
Template:Mono Skip the first SKIP1 bytes of FILE1 and the first SKIP2 bytes of FILE2. No No No No Yes 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.

Yes Yes Yes Yes Yes Yes
Template:Mono Print the line number of the first differing byte. Yes Yes Yes No No No
Template:Mono Compare at most LIMIT bytes. No No No No Yes No
Template:Mono Output nothing; yield exit status only. Yes Yes Yes Yes Yes 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. No No No No No Yes
Template:Mono Output version info. No No No No Yes No
Template:Mono Like -l but prints in hexadecimal and using zero as index for the first byte in the files. No No No Yes No No
Template:Mono For regular files compare file sizes first, and fail the comparison if they are not equal. No No No Yes No No
Template:Mono Outputs a help file. No No No No Yes 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[7] for decimal multiples and with the IEC 60027-2 prefixes for binary multiples.[8]

Example

File:Cmp-example-command-gimp.gif
Example usage of 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

References

Template:Reflist

External links

Template:Sister project

Script error: No such module "Navbox". Template:Plan 9 commands

  1. Script error: No such module "citation/CS1".
  2. Template:Man
  3. Template:Man
  4. Script error: No such module "citation/CS1".
  5. Script error: No such module "citation/CS1".
  6. Script error: No such module "citation/CS1".
  7. Script error: No such module "citation/CS1".
  8. Script error: No such module "citation/CS1".