About Us Documentation

Contact Site Map



Man Page for DIFF


       diff - Compares text files


       diff   [-c | -C number | -e | -f |   -h | -n]   [-bilrstw]
            [-Sfile] directory1 directory2

       diff [-c | -C number | -e | -f  | -h | -n]  [-bitw]  file1

       diff [-Dstring] [-bitw] file1 file2


       The  -c,  -C, -e, -f, -h, and -n flags are mutually exclu-

       The -r, -s, and -S flags can be specified  with  directory
       comparisons only.

       The  -b,  -i, -l, -t, and -w flags can be used in combina-
       tion with any others and in both file and  directory  com-

       -b  Causes trailing white space at the end of a line to be
           treated as a single newline character.

       -c  Produces a listing with the default number of lines of
           context  (3  lines).  The output lists the files being
           compared and their last modification dates, then lists
           the  differing lines.  Lines that are changed from one
           file to the other are marked in both files with  an  !
           (exclamation  point).   Changes  that  lie  within the
           specified number of lines of each  other  are  grouped
           together on output.

       -C number
           Produces  output that provides number lines of context
           (where number is a positive decimal integer).

           Causes diff to create a merged version  of  file1  and
           file2 on the standard output, with C preprocessor con-
           trols included.  Thus, a  compilation  of  the  result
           without  defining  string  is  equivalent to compiling
           file1, while defining string yields file2.

       -e  Produces a script of a, c, d, and s commands  for  the
           editor  ed,  which  can recreate file2 from file1.  In
           connection with -e, the following  shell  program  can
           help  maintain  multiple  versions of a file.  Only an
           ancestral file ($1) and a chain of  version-to-version
           ed scripts ($2, $3, ...) made by diff need be on hand.
           A "latest version" appears on the standard output.
            (shift; cat $*; echo '1,$p') | ed - $1

              Extra commands are added to the output when compar-
              ing  directories with -e; the result is a sh script
              for converting text files common to the directories
              from  their  state  in directory1 to their state in

       -f  Produces a script similar to that of  -e,  not  useful
           with ed, and in the opposite order.

       -h  Performs  a  faster  comparison.  This flag only works
           when the changed sections are  short  and  well  sepa-
           rated,  but  it does work on files of any length.  The
           -e and -f flags are not available when you use the  -h

       -i  Ignores  the  case of letters.  For example, A is con-
           sidered identical to a.

       -l  Specifies long output  format;  each  text  file  diff
           listing is piped through pr to paginate it, other dif-
           ferences are remembered and summarized after all  text
           file differences are reported.  (Directory comparisons

       -n  Produces a script similar to that of -e,  but  in  the
           opposite  order  and  with a count of changed lines on
           each insert or delete command.  This is the form  used
           by the revision control system (RCS).

       -r  Checks files in common subdirectories recursively.

       -s  Reports  identical files, which are otherwise not men-

           Starts a directory diff in the middle, beginning  with
           file.  (Directory comparisons only.)

       -t  Expands  tabs  in  output  lines.  Normal or -c output
           adds characters to the front of  each  line  that  can
           affect  the  indentation  of the original source lines
           and make the output listing  difficult  to  interpret.
           This flag preserves the original source's indentation.

       -w  Is similar to -b, but causes  whitespace  (spaces  and
           tabs)  to  be  ignored.  For example, if ( a == b ) is
           considered identical to if(a==b).


   Input Options
              If neither file1 nor file2  is  a  directory,  then
              either  can be given as - (dash), in which case the
              standard input is used.  If file1  is  a  directory
              and  file2  is a file, or vice versa, a file in the
              specified directory with the same name as the spec-
              ified file is used.

              If  both  arguments are directories, diff sorts the
              contents of the directories by name, and then  runs
              the  regular diff file algorithm on text files that
              are different.  Binary files  that  differ,  common
              subdirectories,  and  files that appear in only one
              directory are also listed.

   Output Options
              There are several choices for output  format.   The
              default  output  format  contains  lines  of  these

            number1 a number2,number3
            number1,number2 d number3
            number1,number2 c number3,number4

              These lines resemble ed commands to  convert  file1
              into  file2.  a indicates that a line or lines were
              added to one of the files; d indicates that a  line
              or  lines were deleted; and c indicates that a line
              or lines were changed.  The numbers after the  let-
              ters  pertain  to  file2.  In fact, by exchanging a
              for  d  and  reading  backward  one  can  ascertain
              equally how to convert file2 into file1.  As in ed,
              identical pairs where number1 = number2 or  number3
              = number4 are abbreviated as a single number.

              Following  each  of  these lines come all the lines
              that are affected in the first file, flagged  by  <
              (left  angle  bracket), then all the lines that are
              affected in the second file, flagged  by  >  (right
              angle bracket).

              Except in rare circumstances, diff finds the small-
              est sufficient set of file differences.


        1.  To compare two files, enter:

            diff chap1.bak chap1

              This displays the  differences  between  the  files
              chap1.bak and chap1.

        2.  To  compare  two  files,  ignoring differences in the
            amount of white space, enter:

            diff -b prog.c.bak prog.c

              If two lines differ only in the  number  of  spaces
              and  tabs between words, then the diff command con-
              siders them to be the same.

        3.  To create a file containing commands that the ed com-
            mand  can  use  to reconstruct one file from another,

            diff -e ch2 ch2.old > new.old.ed

              This creates a file named new.to.old.ed  that  con-
              tains  the ed subcommands to change chap2 back into
              the version of the text  found  in  chap2.old.   In
              most  cases,  new.to.old.ed  is a much smaller file
              than chap2.old.

        4.  You can save disk space by  deleting  chap2.old,  and
            you can reconstruct it at any time by entering:

            (cat new.old.ed ; echo '1,$p') | ed - ch2 > ch2.old

              The  commands in parentheses add 1,$p to the end of
              the editing commands sent to the  ed  editor.   The
              1,$p  causes  the  ed  command to write the file to
              standard output after editing  it.   This  modified
              command  sequence is then piped to the ed command (
              | ed ), and the editor reads it as standard  input.
              The - flag causes the ed command not to display the
              file size and other  extra  information,  since  it
              would be mixed with the text of chap2.old.


                  For the -h flag.

                  For the -l flag.


        1.  Editing scripts produced by the -e or -f flags cannot
            create lines consisting of a single .  (dot)  charac-

        2.  Block,  character,  or  FIFO  special files cannot be
            used with diff because  they  cause  the  command  to

        3.  If  lines  at the end of a file are changed and other
            lines added, diff output may show this  as  a  delete
            and  add,  as  a change, or as a change and add. That
            is, diff is not expected to know what happened.


       An exit value of 0  (zero)  indicates  no  differences,  1
       indicates  differences  found, and a number greater than 1
       indicates an error.


       Commands:    bdiff(1),    cmp(1),    comm(1),    diff3(1),
       ed(1)/red(1), pr(1).  delim off

To return to the Ready-to-Run Software Super ReadyPak Table of Contents please press here.


Email addresses listed on this site may  NOT be used for unsolicited commercial email.

Ready-to-Run Software, Inc Privacy Statement

Portions (c)Copyright, 1996-2005 by Ready-to-Run Software, Inc
(All rights reserved.)
212 Cedar Cove
Lansing, NY 14882
Phone: 607 533 UNIX (8649)
Fax: 607 533 4002