Английская Википедия:Cmp (Unix)
Шаблон:Lowercase title
Шаблон:Infobox software
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
Шаблон:Code 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 Шаблон:Mono command has also been ported to the IBM i operating system.[6]
Switches
cmp
may be qualified by the use of command-line switches. The switches supported by notable implementations of cmp
are:
Name | Description | Unix | Plan 9 | Inferno | FreeBSD | Linux | IBM i |
---|---|---|---|---|---|---|---|
-b,
|
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").
|
Шаблон:No | Шаблон:No | Шаблон:No | Шаблон:No | Шаблон:Yes | Шаблон:No |
-h
|
Do not follow symbolic links. | Шаблон:No | Шаблон:No | Шаблон:No | Шаблон:Yes | Шаблон:No | Шаблон:No |
-i SKIP,
|
Skip the first SKIP bytes of input. | Шаблон:No | Шаблон:No | Шаблон:No | Шаблон:No | Шаблон:Yes | Шаблон:No |
-i SKIP1:SKIP2,
|
Skip the first SKIP1 bytes of FILE1 and the first SKIP2 bytes of FILE2. | Шаблон:No | Шаблон:No | Шаблон:No | Шаблон:No | Шаблон:Yes | Шаблон:No |
-l,
|
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 |
-L
|
Print the line number of the first differing byte. | Шаблон:Yes | Шаблон:Yes | Шаблон:Yes | Шаблон:No | Шаблон:No | Шаблон:No |
-n LIMIT,
|
Compare at most LIMIT bytes. | Шаблон:No | Шаблон:No | Шаблон:No | Шаблон:No | Шаблон:Yes | Шаблон:No |
-s,
|
Output nothing; yield exit status only. | Шаблон:Yes | Шаблон:Yes | Шаблон:Yes | Шаблон:Yes | Шаблон:Yes | Шаблон:Yes |
-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 |
-v,
|
Output version info. | Шаблон:No | Шаблон:No | Шаблон:No | Шаблон:No | Шаблон:Yes | Шаблон:No |
-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 |
-z
|
For regular files compare file sizes first, and fail the comparison if they are not equal. | Шаблон:No | Шаблон:No | Шаблон:No | Шаблон:Yes | Шаблон:No | Шаблон:No |
--help
|
Outputs a help file. | Шаблон:No | Шаблон:No | Шаблон:No | Шаблон:No | Шаблон:Yes | Шаблон:No |
Operands that are byte counts are normally decimal, 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]
Examples
Comparing
:020000040007F3 :10E00000840D80E501000000010000000100000017 :10E01000000000000000000070DE010062A726542E with :020000040007F3 :10E44400840D80E501000000010000000100000017 :10E01000000000000000000070DE010062A726542E > cmp 0 00 0 00 differ: char 21, line 2 > cmp -l 0 00 # note: byte location is in decimal, contents is in octal 21 64 60 22 64 60 23 64 60
Return values
- 0 – files are identical
- 1 – files differ
- 2 – inaccessible or missing argument
See also
References
External links
- Шаблон:Man
- Comparing and Merging Files: Invoking cmp The section of the manual of GNU cmp in the diffutils free manual.
Шаблон:Unix commands Шаблон:Plan 9 commands
- Английская Википедия
- Free file comparison tools
- Standard Unix programs
- Unix SUS2008 utilities
- Plan 9 commands
- Inferno (operating system) commands
- IBM i Qshell commands
- Страницы, где используется шаблон "Навигационная таблица/Телепорт"
- Страницы с телепортом
- Википедия
- Статья из Википедии
- Статья из Английской Википедии