unixdev.net


Switch to SpeakEasy.net DSL

The Modular Manual Browser

Home Page
Manual: (HP-UX-11.11)
Page:
Section:
Apropos / Subsearch:
optional field



 diff(1)							     diff(1)




 NAME
      diff - differential file and directory comparator

 SYNOPSIS
      diff [-C n] [-S name] [-lrs] [-bcefhintw] dir1 dir2

      diff [-C n] [-S name] [-bcefhintw] file1 file2

      diff [-D string] [-biw] file1 file2

 DESCRIPTION
    Comparing Directories
      If both arguments are directories, diff sorts the contents of the
      directories by name, then runs the regular file diff algorithm
      (described below) on text files that have the same name in each
      directory but are different.  Binary files that differ, common
      subdirectories, and files that appear in only one directory are
      listed.  When comparing directories, the following options are
      recognized:

	   -l	       Long output format; each text file diff is piped
		       through pr to paginate it (see pr(1)).  Other
		       differences are remembered and summarized after all
		       text file differences are reported.

	   -r	       Applies diff recursively to common subdirectories
		       encountered.

	   -s	       diff reports files that are identical but otherwise
		       not mentioned.

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

    Comparing Files
      When run on regular files, and when comparing text files that differ
      during directory comparison, diff tells what lines must be changed in
      the files to bring them into agreement.  diff usually finds a smallest
      sufficient set of file differences.  However, it can be misled by
      lines containing very few characters or by other situations.  If
      neither file1 nor file2 is a directory, either can be specified as -,
      in which case the standard input is used.	 If file1 is a directory, a
      file in that directory whose filename is the same as the filename of
      file2 is used (and vice versa).

      There are several options for output format.  The default output
      format contains lines resembling the following:

	   n1 a n3,n4
	   n1,n2 d n3
	   n1,n2 c n3,n4



 Hewlett-Packard Company	    - 1 -   HP-UX Release 11i: November 2000






 diff(1)							     diff(1)




      These lines resemble ed commands to convert file1 into file2.  The
      numbers after the letters pertain to file2.  In fact, by exchanging a
      for d and reading backwards one may ascertain equally how to convert
      file2 into file1.	 As in ed, identical pairs where n1=n2 or n3=n4 are
      abbreviated as a single number.

      Following each of these lines come all the lines that are affected in
      the first file flagged by <&lt&lt&lt;, then all the lines that are affected in
      the second file flagged by >&gt&gt&gt;.

      Except for -b, -w, -i, or -t which can be given with any of the
      others, the following options are mutually exclusive:

	   -e	    Produce a script of a, c, and d commands for the ed
		    editor suitable for recreating file2 from file1.  Extra
		    commands are added to the output when comparing
		    directories with -e, so that the result is a shell
		    script for converting text files common to the two
		    directories from their state in dir1 to their state in
		    dir2 (see sh-bourne(1)

	   -f	    Produce a script similar to that of the -e option that
		    is not useful with ed but is more readable by humans.

	   -n	    Produce 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
		    rcsdiff (see rcsdiff(1)).

	   -c	    Produce a difference list with 3 lines of context.	-c
		    modifies the output format slightly: the output begins
		    with identification of the files involved, followed by
		    their creation dates, then each change separated by a
		    line containing about twelve asterisks (*)s.  Lines
		    removed from file1 are marked with -, and lines added to
		    file2 are marked +.	 Lines that change from one file to
		    the other are marked in both files with with !.  Changes
		    that lie within 3 lines of each other in the file are
		    grouped together on output.

	   -C n	    Output format similar to -c but with n lines of context.

	   -h	    Do a fast, half-hearted job.  This option works only
		    when changed stretches are short and well separated, but
		    can be used on files of unlimited length.

	   -D string
		    Create a merged version of file1 and file2 on the
		    standard output, with C preprocessor controls included
		    so that a compilation of the result without defining
		    string is equivalent to compiling file1, while compiling



 Hewlett-Packard Company	    - 2 -   HP-UX Release 11i: November 2000






 diff(1)							     diff(1)




		    the result with string defined is equivalent to
		    compiling file2.

	   -b	    Ignore trailing blanks (spaces and tabs) and treat other
		    strings of blanks as equal.

	   -w	    Ignore all whitespace (blanks and tabs).  For example,
		    if ( a == b ) and if(a==b) are treated as equal.

	   -i	    Ignores uppercase/lowercase differences.  Thus A is
		    treated the same as a.

	   -t	    Expand tabs in output lines.  Normal or -c output adds
		    one or more characters to the front of each line.
		    Resulting misalignment of indentation in the original
		    source lines can make the output listing difficult to
		    interpret.	This option preserves original source file
		    indentation.

 EXTERNAL INFLUENCES
    Environment Variables
      LANG determines the locale to use for the locale categories when both
      LC_ALL and the corresponding environment variable (beginning with LC_)
      do not specify a locale.	If LANG is not set or is set to the empty
      string, a default of "C" (see lang(5)) is used.

      LC_CTYPE determines the space characters for the diff command, and the
      interpretation of text within file as single- and/or multi-byte
      characters.

      LC_MESSAGES determines the language in which messages are displayed.

      If any internationalization variable contains an invalid setting, diff
      and diffh behave as if all internationalization variables are set to
      "C".  See environ(5).

    International Code Set Support
      Single- and multi-byte character code sets are supported with the
      exception that diff and diffh do not recognize multi-byte alternative
      space characters.

 RETURN VALUE
      Upon completion, diff returns with one of the following exit values:

	    0	   No differences were found.

	    1	   Differences were found.

	   >&gt&gt&gt;1	   An error occurred.





 Hewlett-Packard Company	    - 3 -   HP-UX Release 11i: November 2000






 diff(1)							     diff(1)




 EXAMPLES
      The following command creates a script file script:

	   diff -e x1 x2 >&gt&gt&gt;script

      w is added to the end of the script in order to save the file:

	   echo w >&gt&gt&gt;>&gt&gt&gt; script

      The script file can then be used to create the file x2 from the file
      x1 using the editor ed in the following manner:

	   ed x1 <&lt&lt&lt; script

      The following command produces the difference output with 2 lines of
      context information before and after the line that was different:

	   diff -C2 x1 x2

      The following command ignores all blanks and tabs and ignores
      uppercase-lowercase differences.

	   diff -wi x1 x2

 WARNINGS
      Editing scripts produced by the -e or -f option are naive about
      creating lines consisting of a single dot (.).

      When comparing directories with the -b, -w, or -i options specified,
      diff first compares the files in the same manner as cmp, then runs the
      diff algorithm if they are not equal.  This may cause a small amount
      of spurious output if the files are identical except for insignificant
      blank strings or uppercase/lowercase differences.

      The default algorithm requires memory allocation of roughly six times
      the size of the file.  If sufficient memory is not available for
      handling large files, the -h option or bdiff can be used (see
      bdiff(1)).

      With other options if sufficient memory is not available, then either
      the swap or maxdsiz values can be increased.

      When run on directories with the -r option, diff recursively descends
      sub-trees.  When comparing deep multi-level directories, more memory
      may be required than is currently available on the system.  The amount
      of memory required depends on the depth of recursion and the size of
      the files.

 AUTHOR
      diff was developed by AT&T, the University of California, Berkeley,
      and HP.



 Hewlett-Packard Company	    - 4 -   HP-UX Release 11i: November 2000






 diff(1)							     diff(1)




 FILES
      /usr/lbin/diffh		    used by -h option

 SEE ALSO
      bdiff(1), cmp(1), comm(1), diff3(1), diffmk(1), dircmp(1), ed(1),
      more(1), nroff(1), rcsdiff(1), sccsdiff(1), sdiff(1), terminfo(4).

 STANDARDS CONFORMANCE
      diff: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2













































 Hewlett-Packard Company	    - 5 -   HP-UX Release 11i: November 2000