Hamilton LaboratoriesHamilton C shell 2012User guideExternal utilities

diff

Oregon Coast

diff
Previous | Next

        Compare Files or Directories

Usage:  diff [-bBeEfhiNqrsvw!-] [-m minmatch] [-n maxbest] [-o maxwindow]
                 [-Dstring] [-dstring] oldpath newpath

   diff produces a list of differences between two files or
   directories.  The working assumption is that newpath is a
   newer version of whatever's in oldpath.  If they're files,
   diff assumes they contain ascii text but if it encounters a
   file containing lots of binary data, it switches to a binary
   comparison mode to avoid dumping gibberish to the screen.

   Comparing files, diff looks for minimal sections of change.
   Each difference is shown as an add, delete or change with the
   appropriate line numbers or line number ranges for  each file.
   Following are texts of the differing section.  Lines that have
   been deleted are flagged with '<'; lines that have been added
   are flagged with '>'.  Alternately, diff can be used to produce
   merged listings with #ifdefs for the C compiler or highlighting
   for quick visual scanning.

   The algorithm for comparing files is to maintain sliding
   windows into each of the two files, adding new lines to each
   window until there is a matching sequence of some minimal
   number of lines at the bottom of each window.  That minimum
   can be configured via the -m option.

   Once that minimal match is found, diff begins to compare the
   two windows in an attempt to minimize the number of lines in
   each that cannot be matched against the other.  If the combined
   total number of lines in the two windows is less than some
   heuristic limit, set via the -n option, diff will do this
   comparison with a recursive algorithm guaranteed to find the
   absolute best solution.  But because the computation involved
   in this approach grows very quickly as the number of lines
   increases, diff switches to a heuristic approach for more
   complex window comparisons, breaking the windows down into
   smaller segments against which the exhaustive approach can
   be used.

   Comparing directories, diff builds lists of all the files
   they contain, searching all the way down through the tree.
   The lists are sorted, then compared.  If the same filename
   exists in each directory tree, a quick binary comparison is
   normally made of whether they contain the same or different
   data.  If -r is specified, the diff text comparison is done
   recursively the whole way down the two trees.

   If one of the arguments to diff is a file and the other is a
   directory, diff will look for and compare against a file of
   that same name in the directory.

Options:

   -b           Blank spaces of any length compare equal.  Ignore
                any leading or trailing white space on each line.
   -B           Binary comparison even on text files.
   -Dstring     Produce a merged #ifdef'ed listing, with the string
                being defined meaning use the older version. (Newer
                version is intentionally the default.)
   -dstring     Same as -Dstring, but add comments of the form
                /* string */ to the #else and #endif directives
                that are generated.
   -e           Produce an ed script which, when a w (the write
                command) is appended to it, can be used to
                transform the first file into the second.
   -E           Turn off highlighting of empty lines.  By default,
                if highlighting is used to show areas of change,
                even empty lines will have ANSI sequences at the
                beginning and end so that if more is used to display
                the output with the default color stretch mode on,
                empty lines will still be highlighted.
   -f           Force diff-style comparison to continue even on files
                that appear to contain binary data.
   -h           Help.  (This screen.)
   -i           Ignore character case.
   -m minmatch  Minimum match length to insist on before resynchro-
                nizing two files.  (Default is 20 lines.)
   -n maxbest   Maximum total number of lines in the two windows
                against which diff will attempt an absolute best
                match.  If the total is larger, it will attempt
                to break the problem down with heuristics.
                (Default is 15 lines.)
   -N           Ignore differences in line endings.  NewLine and
                CarriageReturn-NewLine endings will be considered
                equal.
   -o maxwindow Maximum total number of lines that diff will
                allow to be collected into the two windows before
                it gives up looking for a resynchronizing match.
                (Default is 4000 lines.)
   -q           Quiet:  suppress warnings about files containing
                binary data.
   -r           Recursively diff the contents of any subdirectories.
   -s           Add spaces to separate the a (add), c (change) or d
                (delete) characters from the line numbers in a diff
                report for better readability.
   -v           Verbose listing of all the contents of any entire
                subdirectory added or deleted.
   -w           White space is ignored totally.
   -!           Produce merged, highlighted version.  Text that's
                unchanged is normal, deleted text is red, new text
                is green.
   --           End of options.

Colors:

   You may set your own choices for screen colors using these
   environmental variables:

      Name         Use                      Default
      COLORS       Normal screen colors     <null string>
      ADDITIONS    Lines added              Bright White on Green
      DELETIONS    Lines deleted            Bright White on Red

   Colors recognized are black, red, green, yellow, blue, magenta
   (or red blue), cyan (or blue green) or white.  Foreground and
   background colors may also be bright, dim or reverse.  The names
   of the colors and the words bright, dim, reverse and on may be
   in either upper or lower or mixed case.

   Either or both the foreground and background colors may be
   specified; if you don't specify a value, it's considered
   transparent and inherits the color underneath it.   ADDITIONS
   and DELETIONS inherit from COLORS.  If COLORS is null, diff
   uses the current screen colors it finds at startup.

Previous | Next