Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ diff(1) — Reliant UNIX 5.44c4

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

bdiff(1)

cmp(1)

comm(1)

diff3(1)

dircmp(1)

ed(1)

pr(1)

diff(1)                                                             diff(1)

NAME
     diff - differential file comparator

SYNOPSIS
     diff [option ...] file1 file2

DESCRIPTION
     The diff utility will compare the contents of file1 and file2 and
     write to standard output a list of changes necessary to convert file1
     into file2. This list should be minimal. No output will be produced if
     the files are identical.

OPTIONS
     No option specified:
          If the compared files are identical, diff produces no output.
          When the files differ, the output is as follows:

          1.  line[range] from   ed command   line[range] from
              file1                           file2

          2.  lines that are only in file1

          3.  lines that are only in file2

          The lines are displayed in the following format:

                        a
          1.  n1[,n2]   d   n1[,n2]
                        c

          2.  < text of line from file1
                   .
                   .
                   .
                   - - -

          3.  > text of line from file2
                   .
                   .
                   .

          a, d, and c are ed-like commands meaning:

          a  append

          d  delete

          c  change







Page 1                       Reliant UNIX 5.44                Printed 11/98

diff(1)                                                             diff(1)

          The output is to be interpreted as follows:

          The ed commands a, d, and c with their preceding line (or range)
          specifications show how file1 can be converted into file2.

          If you replace a with d and d with a and use the line (or range)
          specifications to the right, the commands indicate how file2 can
          be converted into file1. Lines from file1 are marked <; those
          from file2 are marked >.

     -a   This option produces a diff with all lines of context from both
          files. Those lines only in file1 are prepended with -; those only
          in file2 are prepended with +. Lines which are identical in both
          files are prepended with a <blank>.

     -b   diff ignores trailing blanks or tabs at the end of lines as well
          as differing numbers of blanks at corresponding positions within
          text lines. Leading blanks and blank lines are reported as dif-
          ferences.

     -i   -i must not be combined with -h.

          diff ignores the case of letters; for example, it considers "A"
          to be the same as "a".

     -t   diff expands tab characters in output lines. In normal or -c out-
          put, diff adds character(s) to the start of each line that may
          adversely affect the indentation of the original source lines and
          make the output lines difficult to interpret. The -t option pre-
          serves the original source's indentation.

     -w   diff ignores all blanks (space and tab characters) and treats
          strings of blanks of any length as equivalent; for example, it
          considers "if ( a = = b )" to be the same as "if(a==b)".

     The following options are mutually exclusive:

     -c   diff produces a listing in three parts with a slightly modified
          output format. The output begins with the names and creation
          dates of file1 and file2. Then come the lines that differ, with
          the lines not present in file2 marked with a minus sign (-) and
          the lines that differ in file1 and file2 marked with an exclama-
          tion point (!). There are also three lines of context before and
          after the differing lines.

     -C number
          Produces a listing of differences identical to that produced by
          -c, but with number lines of context before and after each dif-
          ference.





Page 2                       Reliant UNIX 5.44                Printed 11/98

diff(1)                                                             diff(1)

     -e   The -e option must not be combined with -h, -l or -s.

          diff produces output suitable for use as an ed script. The ed
          script contains a, d, and c commands and the related text lines
          as input for the editor ed to convert file1 to file2. Before you
          pass the script to the editor, you should add the statements w
          and q at the end of the script and insert the command e file1 at
          the start [see ed(1)].

     -f   The -f option must not be combined with option -h.

          diff generates a similar script to the one created with option
          -e, but converting in the opposite direction. This script, how-
          ever, is not usable with ed.

          Editing scripts produced under the -e and -f options may be
          incorrect when dealing with lines comprising nothing but a single
          period.

     The following options modify the way in which diff works:

     -h   The -h option must not be combined with -e, -f, -i, -c, -C, -n or
          -D.

          diff operates faster, and you can process files of any length.
          However, the result produced by option -h is not reliable!

     -n   Produces a script similar to -e, but with the ed commands listed
          in reverse order. In addition, a count of the lines to be changed
          is printed after each insert or delete command.

     -D string
          In this case file1 and file2 must be C source programs or contain
          C source fragments.

          diff creates a merged version of file1 and file2 with C prepro-
          cessor controls included so that compilation of the result is
          equivalent to compiling file1 if string is not defined, and is
          equivalent to compiling file2 if string is defined.

     The following options are used to compare directories:

     -l   diff produces output in long format. Before checking for differ-
          ences, diff pipes each text file through pr to paginate it. Dif-
          ferences other than those in text files are remembered and are
          summarized after all text file differences have been reported.

     -r   Applies diff recursively to all common subdirectories encoun-
          tered.

     -s   Reports files that are identical; these would not otherwise be
          mentioned.


Page 3                       Reliant UNIX 5.44                Printed 11/98

diff(1)                                                             diff(1)

     -S name
          Starts a directory diff in the middle, beginning with the file
          name.

     --   If file1 begins with a dash (-), the end of the command-line
          options must be marked with --.

     file1 file2
          Names of the files diff is to compare. If file1 is a directory,
          then a file in that directory with the same name as file2 is com-
          pared against file2. If file2 is a directory, then the comparison
          is made with a file named file1 from that directory.

EXIT STATUS
     0   Files are the same

     1   Files are different

     >1  Input error

ERROR MESSAGES

     diff: two filename arguments required

     You have specified an incorrect number of files. Only two files can be
     compared at a time.

     diff: No such file or directory

     One of the specified files does not exist.

     diff: files too big, try -h

     You need to use the -h option, as the files to be compared are too
     large.

     diff: Permission denied

     You do not have read permission for one of the specified files.

LOCALE
     The LCMESSAGES environment variable governs the language in which
     message texts are displayed. If LCMESSAGES is undefined or is defined
     as the null string, it defaults to the value of LANG. If LANG is like-
     wise undefined or null, the system acts as if it were not internation-
     alized.

     The LCALL environment variable governs the entire locale. LCALL
     takes precedence over all the other environment variables which affect
     internationalization.




Page 4                       Reliant UNIX 5.44                Printed 11/98

diff(1)                                                             diff(1)

EXAMPLES
     Example 1

     The files file1 and file2 have the following contents:

     file1                file2

     Jack Jill            Jack and Jill
     went up the hill     went uphill
     to fetch a pail      of water
     of water

     By calling diff, you can identify the lines in which the two files
     differ.

     $ diff file1 file2
     1,3c1,2
     <Jack Jill
     <went up the hill
     <to fetch a pail
     ---
     >Jack and Jill
     >went uphill

     Explanation: In order to convert file1 into file2, lines 1 to 3
     inclusive from file1 (1,3) must be replaced (c) by lines 1 to 2
     inclusive (1,2) of file2. The contents of each of these lines are
     shown in the output lines beginning with the < or > characters. Lines
     in file1 are marked <; lines in file2 are marked >.

     Example 2

     Compare files and produce an ed script:

     Contents of file1:      Contents of file2:

     today is Monday         today is Tuesday
     it is cold              it is autumn
                             it is cold

     After the following command, diff outputs the ed commands with which
     ed could convert file1 into file2. To be able to use this output as
     input for ed, you need to add the statements w and q to the end of the
     ed script.

     $ diff -e file1 file2
     1c
     today is Tuesday
     it is autumn
     .
     $



Page 5                       Reliant UNIX 5.44                Printed 11/98

diff(1)                                                             diff(1)

SEE ALSO
     bdiff(1), cmp(1), comm(1), diff3(1), dircmp(1), ed(1), pr(1).




















































Page 6                       Reliant UNIX 5.44                Printed 11/98

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026