Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

cmp (Unix)

From Wikipedia, the free encyclopedia
File comparison command
cmp
Original authorsDennis Ritchie
(AT&T Bell Laboratories)
DevelopersVariousopen-source andcommercial developers
Initial releaseNovember 3, 1971; 54 years ago (1971-11-03)
Written inPlan 9:C
Operating systemUnix,Unix-like,Plan 9,Inferno,OS-9,IBM i
TypeCommand
Licensecoreutils:GPLv3+
Plan 9:MIT License

cmp is ashellcommand that compares twofiles of anytype and reports differences. By default, it outputs nothing if the files match. If they differ, it reports thebyte and line number of the first difference. Theexit code can be used programmatically since it is 0 if the files match, 1 if the files differ or 2 if comparison fails (i.e. inaccessible or missing argument).

The command is available onUnix-like systems,OS-9,IBM i andWindows (viaUnxUtils).[1][2][3] The command first appeared inVersion 1 Unix.[4] It is part of theX/Open Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and theSingle Unix Specification.[5] The implementation inGNUcoreutils was written by Torbjorn Granlund and David MacKenzie.[6]

Use

[edit]

Command line options include:

OptionDescriptionUnixPlan 9InfernoFreeBSDLinuxIBM i
-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")NoNoNoNoYesNo
-hDo not follow symbolic linksNoNoNoYesNoNo
-i SKIP,
--ignore-initial=SKIP
Skip the first SKIP bytes of inputNoNoNoNoYesNo
-i SKIP1:SKIP2,
--ignore-
initial=
SKIP1:SKIP2
Skip the first SKIP1 bytes of FILE1 and the first SKIP2 bytes of FILE2NoNoNoNoYesNo
-l,
--verbose
Print the (decimal) byte numbers and (octal) values of all differing bytes, instead of the default info; also, print the EOF message if one file is shorter than the otherYesYesYesYesYesYes
-LPrint the line number of the first differing byteYesYesYesNoNoNo
-n LIMIT,
--bytes=LIMIT
Compare at most LIMIT bytesNoNoNoNoYesNo
-s,
--quiet,
--silent
Print nothing; yield exit status onlyYesYesYesYesYesYes
-tText mode where the files are opened in text mode and translated to theCCSID of the job before comparing byte for byteNoNoNoNoNoYes
-v,
--version
Print version infoNoNoNoNoYesNo
-xLike -l but prints in hexadecimal and using zero as index for the first byte in the filesNoNoNoYesNoNo
-zFor regular files, compare file sizes first, and fail if they are not equalNoNoNoYesNoNo
--helpPrint command-line help infoNoNoNoNoYesNo

Operands that are byte counts are decimal by default, 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[7] for decimal multiples and with the IEC 60027-2 prefixes for binary multiples.[8]

Example

[edit]
Example use to report different bytes between text files

See also

[edit]

References

[edit]
  1. ^Paul S. Dayan (1992).The OS-9 Guru - 1 : The Facts. Galactic Industrial Limited.ISBN 0-9519228-0-7.
  2. ^IBM."IBM System i Version 7.2 Programming Qshell"(PDF).IBM. Retrieved2020-09-05.
  3. ^"Native Win32 ports of some GNU utilities".unxutils.sourceforge.net.
  4. ^cmp(1) – FreeBSD General CommandsManual
  5. ^printf – Shell and Utilities Reference,The Single UNIX Specification, Version 5 fromThe Open Group
  6. ^"cmp(1): compare two files byte by byte - Linux man page".linux.die.net.
  7. ^"Welcome - BIPM".
  8. ^"Definitions of the SI units: The binary prefixes".physics.nist.gov. Retrieved21 April 2018.

External links

[edit]
The WikibookGuide to Unix has a page on the topic of:Commands
File system
Processes
User environment
Text processing
Shell builtins
Searching
Documentation
Software development
Miscellaneous
File system
Processes
User environment
Text processing
Shell builtins
Networking
Searching
Software development
Miscellaneous
Retrieved from "https://en.wikipedia.org/w/index.php?title=Cmp_(Unix)&oldid=1305040458"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp