Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 History  





2 Switches  





3 Example  





4 Return values  





5 See also  





6 References  





7 External links  














cmp (Unix)






العربية
Беларуская
Català
Čeština
Ελληνικά
Español
فارسی

Italiano
Magyar

Português
Română
Русский
Türkçe
Українська
Tiếng Vit

 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 


cmp
Original author(s)Dennis Ritchie
(AT&T Bell Laboratories)
Developer(s)Various open-source and commercial developers
Initial releaseNovember 3, 1971; 52 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

Incomputing, 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[edit]

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 cmp command has also been ported to the IBM i operating system.[6]

Switches[edit]

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-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"). No No No No Yes No
-h Do not follow symbolic links. No No No Yes No No
-i SKIP,
--ignore-initial=SKIP
Skip the first SKIP bytes of input. No No No No Yes No
-i SKIP1:SKIP2,
--ignore-initial=SKIP1:SKIP2
Skip the first SKIP1 bytes of FILE1 and the first SKIP2 bytes of FILE2. No No No No Yes No
-l,
--verbose
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,
--bytes=LIMIT
Compare at most LIMIT bytes. No No No No Yes No
-s,
--quiet,
--silent
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,
--version
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]

Example[edit]

Example usage of cmp to find different bytes between 2 txt files

Return values[edit]

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.
  • ^ printf – Shell and Utilities Reference, The Single UNIX Specification, Version 4 from The Open Group
  • ^ cmp(1) – FreeBSD General Commands Manual
  • ^ "cmp(1): compare two files byte by byte - Linux man page". linux.die.net.
  • ^ "Native Win32 ports of some GNU utilities". unxutils.sourceforge.net.
  • ^ IBM. "IBM System i Version 7.2 Programming Qshell" (PDF). IBM. Retrieved 2020-09-05.
  • ^ "Welcome - BIPM".
  • ^ "Definitions of the SI units: The binary prefixes". physics.nist.gov. Retrieved 21 April 2018.
  • External links[edit]


    Retrieved from "https://en.wikipedia.org/w/index.php?title=Cmp_(Unix)&oldid=1226206045"

    Categories: 
    Free file comparison tools
    Standard Unix programs
    Unix SUS2008 utilities
    Plan 9 commands
    Inferno (operating system) commands
    IBM i Qshell commands
    Hidden categories: 
    Articles with short description
    Short description is different from Wikidata
     



    This page was last edited on 29 May 2024, at 05:38 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki