Visit Our UNIX and Linux User Community

Linux and UNIX Man Pages

Test Your Knowledge in Computers #64
Difficulty: Easy
HTTP uses UDP as the core transport protocol on the Internet.
True or False?
Linux & Unix Commands - Search Man Pages

cmp(1) [sunos man page]

cmp(1)								   User Commands							    cmp(1)

NAME
cmp - compare two files SYNOPSIS
cmp [-l] [-s] file1 file2 [skip1] [skip2] DESCRIPTION
The cmp utility compares two files. cmp will write no output if the files are the same. Under default options, if they differ, it writes to standard output the byte and line numbers at which the first difference occurred. Bytes and lines are numbered beginning with 1. If one file is an initial subsequence of the other, that fact is noted. skip1 and skip2 are initial byte offsets into file1 and file2 respec- tively, and may be either octal or decimal; a leading 0 denotes octal. OPTIONS
The following options are supported: -l Write the byte number (decimal) and the differing bytes (octal) for each difference. -s Write nothing for differing files; return exit statuses only. OPERANDS
The following operands are supported: file1 A path name of the first file to be compared. If file1 is -, the standard input will be used. file2 A path name of the second file to be compared. If file2 is -, the standard input will be used. If both file1 and file2 refer to standard input or refer to the same FIFO special, block special or character special file, an error results. USAGE
See largefile(5) for the description of the behavior of cmp when encountering files greater than or equal to 2 Gbyte (2**31 bytes). EXAMPLES
Example 1: Comparing files byte for byte The following example: example% cmp file1 file2 0 1024 does a byte for byte comparison of file1 and file2. It skips the first 1024 bytes in file2 before starting the comparison. ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of cmp: LANG, LC_ALL, LC_CTYPE, LC_MES- SAGES, and NLSPATH. EXIT STATUS
The following error values are returned: 0 The files are identical. 1 The files are different; this includes the case where one file is identical to the first part of the other. >1 An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |enabled | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
comm(1), diff(1), attributes(5), environ(5), largefile(5), standards(5) SunOS 5.10 1 Feb 1995 cmp(1)

Check Out this Related Man Page

CMP(1P) 						     POSIX Programmer's Manual							   CMP(1P)

PROLOG
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the correspond- ing Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. NAME
cmp -- compare two files SYNOPSIS
cmp [-l|-s] file1 file2 DESCRIPTION
The cmp utility shall compare two files. The cmp utility shall write no output if the files are the same. Under default options, if they differ, it shall write to standard output the byte and line number at which the first difference occurred. Bytes and lines shall be num- bered beginning with 1. OPTIONS
The cmp utility shall conform to the Base Definitions volume of POSIX.1-2008, Section 12.2, Utility Syntax Guidelines. The following options shall be supported: -l (Lowercase ell.) Write the byte number (decimal) and the differing bytes (octal) for each difference. -s Write nothing for differing files; return exit status only. OPERANDS
The following operands shall be supported: file1 A pathname of the first file to be compared. If file1 is '-', the standard input shall be used. file2 A pathname of the second file to be compared. If file2 is '-', the standard input shall be used. If both file1 and file2 refer to standard input or refer to the same FIFO special, block special, or character special file, the results are undefined. STDIN
The standard input shall be used only if the file1 or file2 operand refers to standard input. See the INPUT FILES section. INPUT FILES
The input files can be any file type. ENVIRONMENT VARIABLES
The following environment variables shall affect the execution of cmp: LANG Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1-2008, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.) LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. ASYNCHRONOUS EVENTS
Default. STDOUT
In the POSIX locale, results of the comparison shall be written to standard output. When no options are used, the format shall be: "%s %s differ: char %d, line %d ", file1, file2, <byte number>, <line number> When the -l option is used, the format shall be: "%d %o %o ", <byte number>, <differing byte>, <differing byte> for each byte that differs. The first <differing byte> number is from file1 while the second is from file2. In both cases, <byte number> shall be relative to the beginning of the file, beginning with 1. No output shall be written to standard output when the -s option is used. STDERR
The standard error shall be used only for diagnostic messages. If the -l option is used and file1 and file2 differ in length, or if the -s option is not used and file1 and file2 are identical for the entire length of the shorter file, in the POSIX locale the following diagnos- tic message shall be written: "cmp: EOF on %s%s ", <name of shorter file>, <additional info> The <additional info> field shall either be null or a string that starts with a <blank> and contains no <newline> characters. Some imple- mentations report on the number of lines in this case. OUTPUT FILES
None. EXTENDED DESCRIPTION
None. EXIT STATUS
The following exit values shall be returned: 0 The files are identical. 1 The files are different; this includes the case where one file is identical to the first part of the other. >1 An error occurred. CONSEQUENCES OF ERRORS
Default. The following sections are informative. APPLICATION USAGE
Although input files to cmp can be any type, the results might not be what would be expected on character special device files or on file types not described by the System Interfaces volume of POSIX.1-2008. Since this volume of POSIX.1-2008 does not specify the block size used when doing input, comparisons of character special files need not compare all of the data in those files. For files which are not text files, line numbers simply reflect the presence of a <newline>, without any implication that the file is orga- nized into lines. EXAMPLES
None. RATIONALE
The global language in Section 1.4, Utility Description Defaults indicates that using two mutually-exclusive options together produces unspecified results. Some System V implementations consider the option usage: cmp -l -s ... to be an error. They also treat: cmp -s -l ... as if no options were specified. Both of these behaviors are considered bugs, but are allowed. The word char in the standard output format comes from historical usage, even though it is actually a byte number. When cmp is supported in other locales, implementations are encouraged to use the word byte or its equivalent in another language. Users should not interpret this difference to indicate that the functionality of the utility changed between locales. Some implementations report on the number of lines in the identical-but-shorter file case. This is allowed by the inclusion of the <addi- tional info> fields in the output format. The restriction on having a leading <blank> and no <newline> characters is to make parsing for the filename easier. It is recognized that some filenames containing white-space characters make parsing difficult anyway, but the restric- tion does aid programs used on systems where the names are predominantly well behaved. FUTURE DIRECTIONS
None. SEE ALSO
comm, diff The Base Definitions volume of POSIX.1-2008, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2013 Edition, Standard for Information Technol- ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, Copyright (C) 2013 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. (This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Stan- dard is the referee document. The original Standard can be obtained online at http://www.unix.org/online.html . Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html . IEEE
/The Open Group 2013 CMP(1P)

Featured Tech Videos