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



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.


NNAAMMEE
       cmp -- compare two files

SSYYNNOOPPSSIISS
       cmp [[-l|-s]] _f_i_l_e_1 _f_i_l_e_2

DDEESSCCRRIIPPTTIIOONN
       The _c_m_p utility shall compare two files. The _c_m_p 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 numbered
       beginning with 1.

OOPPTTIIOONNSS
       The _c_m_p utility shall conform to the Base Definitions volume of
       POSIX.1-2008, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x _G_u_i_d_e_l_i_n_e_s.

       The following options shall be supported:

       --ll        (Lowercase ell.) Write the byte number (decimal) and the
                 differing bytes (octal) for each difference.

       --ss        Write nothing for differing files; return exit status only.

OOPPEERRAANNDDSS
       The following operands shall be supported:

       _f_i_l_e_1     A pathname of the first file to be compared. If _f_i_l_e_1 is ''--'',
                 the standard input shall be used.

       _f_i_l_e_2     A pathname of the second file to be compared. If _f_i_l_e_2 is
                 ''--'', the standard input shall be used.

       If both _f_i_l_e_1 and _f_i_l_e_2 refer to standard input or refer to the same
       FIFO special, block special, or character special file, the results are
       undefined.

SSTTDDIINN
       The standard input shall be used only if the _f_i_l_e_1 or _f_i_l_e_2 operand
       refers to standard input. See the INPUT FILES section.

IINNPPUUTT FFIILLEESS
       The input files can be any file type.

EENNVVIIRROONNMMEENNTT VVAARRIIAABBLLEESS
       The following environment variables shall affect the execution of _c_m_p:

       _L_A_N_G      Provide a default value for the internationalization
                 variables that are unset or null. (See the Base Definitions
                 volume of POSIX.1-2008, _S_e_c_t_i_o_n _8_._2, _I_n_t_e_r_n_a_t_i_o_n_a_l_i_z_a_t_i_o_n
                 _V_a_r_i_a_b_l_e_s for the precedence of internationalization
                 variables used to determine the values of locale categories.)

       _L_C___A_L_L    If set to a non-empty string value, override the values of
                 all the other internationalization variables.

       _L_C___C_T_Y_P_E  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).

       _L_C___M_E_S_S_A_G_E_S
                 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.

       _N_L_S_P_A_T_H   Determine the location of message catalogs for the processing
                 of _L_C___M_E_S_S_A_G_E_S.

AASSYYNNCCHHRROONNOOUUSS EEVVEENNTTSS
       Default.

SSTTDDOOUUTT
       In the POSIX locale, results of the comparison shall be written to
       standard output. When no options are used, the format shall be:

           ""%%ss %%ss ddiiffffeerr:: cchhaarr %%dd,, lliinnee %%dd\\nn"",, _f_i_l_e_1, _f_i_l_e_2,
               <_b_y_t_e _n_u_m_b_e_r>, <_l_i_n_e _n_u_m_b_e_r>

       When the --ll option is used, the format shall be:

           ""%%dd %%oo %%oo\\nn"",, <<_b_y_t_e _n_u_m_b_e_r>, <_d_i_f_f_e_r_i_n_g _b_y_t_e>,
               <_d_i_f_f_e_r_i_n_g _b_y_t_e>

       for each byte that differs. The first <_d_i_f_f_e_r_i_n_g _b_y_t_e> number is from
       _f_i_l_e_1 while the second is from _f_i_l_e_2.  In both cases, <_b_y_t_e _n_u_m_b_e_r>
       shall be relative to the beginning of the file, beginning with 1.

       No output shall be written to standard output when the --ss option is
       used.

SSTTDDEERRRR
       The standard error shall be used only for diagnostic messages. If the
       --ll option is used and _f_i_l_e_1 and _f_i_l_e_2 differ in length, or if the --ss
       option is not used and _f_i_l_e_1 and _f_i_l_e_2 are identical for the entire
       length of the shorter file, in the POSIX locale the following
       diagnostic message shall be written:

           ""ccmmpp:: EEOOFF oonn %%ss%%ss\\nn"",, <<_n_a_m_e _o_f _s_h_o_r_t_e_r _f_i_l_e>, <_a_d_d_i_t_i_o_n_a_l _i_n_f_o>

       The <_a_d_d_i_t_i_o_n_a_l _i_n_f_o> field shall either be null or a string that
       starts with a <blank> and contains no <newline> characters. Some
       implementations report on the number of lines in this case.

OOUUTTPPUUTT FFIILLEESS
       None.

EEXXTTEENNDDEEDD DDEESSCCRRIIPPTTIIOONN
       None.

EEXXIITT SSTTAATTUUSS
       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.

CCOONNSSEEQQUUEENNCCEESS OOFF EERRRROORRSS
       Default.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       Although input files to _c_m_p 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
       organized into lines.

EEXXAAMMPPLLEESS
       None.

RRAATTIIOONNAALLEE
       The global language in _S_e_c_t_i_o_n _1_._4, _U_t_i_l_i_t_y _D_e_s_c_r_i_p_t_i_o_n _D_e_f_a_u_l_t_s
       indicates that using two mutually-exclusive options together produces
       unspecified results. Some System V implementations consider the option
       usage:

           ccmmpp --ll --ss ......

       to be an error. They also treat:

           ccmmpp --ss --ll ......

       as if no options were specified. Both of these behaviors are considered
       bugs, but are allowed.

       The word cchhaarr in the standard output format comes from historical
       usage, even though it is actually a byte number. When _c_m_p is supported
       in other locales, implementations are encouraged to use the word _b_y_t_e
       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
       <_a_d_d_i_t_i_o_n_a_l _i_n_f_o> 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 restriction does aid programs used on systems where the names are
       predominantly well behaved.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _c_o_m_m, _d_i_f_f

       The Base Definitions volume of POSIX.1-2008, _C_h_a_p_t_e_r _8, _E_n_v_i_r_o_n_m_e_n_t
       _V_a_r_i_a_b_l_e_s, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x _G_u_i_d_e_l_i_n_e_s

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- 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 Standard
       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(1)
