*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->OpenBSD man pages -> diff (1)              
Title
Content
Arch
Section
 

DIFF(1)

Contents


NAME    [Toc]    [Back]

     diff - differential file and directory comparator

SYNOPSIS    [Toc]    [Back]

     diff [-abdilpqtTw] [-I pattern] [-c | -e | -f | -n | -u] [-L
label] file1
          file2
     diff  [-abdilpqtTw]  [-I pattern] [-L label] -C number file1
file2
     diff [-abdilqtw] [-I pattern] -D string file1 file2
     diff [-abdilpqtTw] [-I pattern] [-L label] -U  number  file1
file2
     diff  [-abdilNPpqtTw]  [-I pattern] [-c | -e | -f | -n | -u]
[-L label]
          [-r] [-s] [-S name] [-X file] [-x pattern] dir1 dir2

DESCRIPTION    [Toc]    [Back]

     The diff utility compares the contents of  file1  and  file2
and writes to
     the standard output the list of changes necessary to convert
one file into
 the other.  No output is produced if the files are  identical.

     Output options (mutually exclusive):

     -c       Produces  a  diff with 3 lines of context.  With -c
the output format
 is modified slightly:  the  output  begins  with
identification
             of  the  files involved and their creation dates and
then each
             change is separated by a line with fifteen *'s.  The
lines removed
  from  file1 are marked with `- '; those added
to file2 are
             marked `+ '.  Lines which are changed from one  file
to the other
             are  marked  in both files with `! '.  Changes which
lie within 3
             lines of each other are grouped together on  output.

     -e       Produces output in a form suitable as input for the
editor utility,
 ed(1), which can then be used to  convert  file1
into file2.

             Extra  commands are added to the output when comparing directories
             with -e, so that the result is a  sh(1)  script  for
converting text
             files  which  are common to the two directories from
their state in
             dir1 to their state in dir2.

     -f      Identical output to that of the -e flag, but in  reverse order.
             It cannot be digested by ed(1).

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

     -q       Just  print a line when the files differ.  Does not
output a list
             of changes.

     -u      Produces a unified diff with 3 lines of context.   A
unified diff
             is  similar  to  the context diff produced by the -c
option.  However,
 unlike with -c, all lines to be  changed  (added
and/or removed)
 are present in a single section.

     -C number
             Like  -c  but  produces  a diff with number lines of
context.

     -D string
             Creates 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 defining string will yield file2.

     -U number
             Like  -u  but  produces  a diff with number lines of
context.

     Comparison options:

     -a      Treat all files as ASCII.

     -b      Causes trailing blanks (spaces and tabs) to  be  ignored, and other
             strings of blanks to compare equal.

     -d       Try  very hard to produce a diff as small as possible.  This may
             consume a lot of processing power  and  memory  when
processing
             large files with many changes.

     -I pattern
             Ignores  changes,  insertions,  and  deletions whose
lines match the
             extended regular expression  pattern.   Multiple  -I
patterns may be
             specified.   All lines in the change must match some
pattern for
             the change to be ignored.  See re_format(7) for more
information
             on regular expression patterns.

     -i       Ignores the case of letters.  E.g., ``A'' will compare equal to
             ``a''.

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

     -L label
             Print label instead of the first file name and  time
in the context
 or unified diff header.

     -p       With  unified  and  context  diffs,  show with each
change the first
             40 characters of the last line  before  the  context
beginning with
             a  letter,  an  underscore  or a dollar sign.  For C
source code following
 standard layout conventions, this  will  show
the prototype
             of the function the change applies to.

     -t      Will expand tabs in output lines.  Normal or -c output adds character(s)
 to the front of each line which  may  screw
up the indentation
  of  the  original  source lines and make the
output listing
             difficult to interpret.  This option  will  preserve
the original
             source's indentation.

     -T       Print  a tab rather than a space before the rest of
the line for
             the normal, context or unified output formats.  This
makes the
             alignment of tabs in the line consistent.

     -w       Is  similar to -b but causes whitespace (blanks and
tabs) to be
             totally ignored.  E.g., ``if ( a == b )'' will  compare equal to
             ``if(a==b)''.

     Directory comparison options:

     -N       If a file is found in only one directory, act as if
it was found
             in the other directory too but was of zero size.

     -P      If a file is found only in dir2, act as  if  it  was
found in dir1
             too but was of zero size.

     -r       Causes  application  of  diff recursively to common
subdirectories
             encountered.

     -s      Causes diff to report  files  which  are  the  same,
which are otherwise
 not mentioned.

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

     -X file
             Exclude files  and  subdirectories  from  comparison
whose basenames
             match  lines  in  file.   Multiple -X options may be
specified.

     -x pattern
             Exclude files  and  subdirectories  from  comparison
whose basenames
             match  pattern.   Patterns  are matched using shellstyle globbing
             via fnmatch(3).  Multiple -x options may  be  specified.

     If  both  arguments are directories, diff sorts the contents
of the directories
 by name, and then runs the regular  file  diff  algorithm, producing
     a  change  list,  on text files which are different.  Binary
files which
     differ, common subdirectories, and files which appear in only one directory
  are described as such.  In directory mode only regular
files and directories
 are compared.  If a non-regular file such as a device special
     file  or FIFO is encountered, a diagnostic message is printed.

     If only one of file1 and file2 is a directory, diff  is  applied to the
     non-directory  file  and the file contained in the directory
file with a
     filename that is the same as the last component of the  nondirectory
     file.

     If  either file1 or file2 is `-', the standard input is used
in its place.

   Output Style    [Toc]    [Back]
     The default (without -e, -c, or -n options) output  contains
lines of
     these  forms,  where XX, YY, ZZ, QQ are line numbers respective of file order.


     XXaYY        At (the end of) line XX of  file1,  append  the
contents of
                  line YY of file2 to make them equal.
     XXaYY,ZZ      Same  as above, but append the range of lines,
YY through ZZ
                  of file2 to line XX of file1.
     XXdYY        At line XX delete the line.  The value YY tells
to which
                  line  the change would bring file1 in line with
file1.
     XX,YYdZZ     Delete the range of  lines  XX  through  YY  in
file1.
     XXcYY         Change  the line XX in file1 to the line YY in
file2.
     XX,YYcZZ     Replace the range of specified lines  with  the
line ZZ.
     XX,YYcZZ,QQ   Replace  the  range  XX,YY from file1 with the
range ZZ,QQ from
                  file2.

     These lines resemble ed(1) subcommands to convert file1 into
file2.  The
     line  numbers  before  the  action letters pertain to file1;
those after pertain
 to file2.  Thus, by exchanging a for d and reading  the
line in reverse
 order, one can also determine how to convert file2 into file1.  As
     in ed(1), identical pairs (where num1 = num2) are abbreviated as a single
     number.

ENVIRONMENT    [Toc]    [Back]

     TMPDIR  If the environment variable TMPDIR exists, diff will
use the directory
 specified by TMPDIR as the temporary  directory.

FILES    [Toc]    [Back]

     /tmp/diff.XXXXXXXX  Temporary file used when comparing a device or the
                         standard input.  Note that the temporary
file is unlinked
  as  soon  as it is created so it
will not show
                         up in a directory listing.

DIAGNOSTICS    [Toc]    [Back]

     The diff utility exits with one of the following values:

           0       No differences were found.
           1       Differences were found.
           >1      An error occurred.

SEE ALSO    [Toc]    [Back]

      
      
     cmp(1), comm(1), diff3(1), ed(1), pr(1), fnmatch(3), re_format(7)

STANDARDS    [Toc]    [Back]

     The  diff  utility  is expected to be a superset of the IEEE
Std 1003.1-2001
     (``POSIX'') specification.

HISTORY    [Toc]    [Back]

     A diff command appeared in Version 6 AT&T UNIX.

BUGS    [Toc]    [Back]

     When comparing directories with the -b,  -w  or  -i  options
specified, diff
     first compares the files ala cmp(1), and then decides to run
the diff algorithm
 if they are not  equal.   This  may  cause  a  small
amount of spurious
     output  if  the  files then turn out to be identical because
the only differences
 are insignificant whitespace or case differences.

OpenBSD     3.6                           July      21,      2003
[ Back ]
 Similar pages
Name OS Title
diff3 IRIX 3-way differential file comparison
diff3 HP-UX 3-way differential file comparison
diff3 OpenBSD 3-way differential file comparison
xdiff IRIX X11/Motif based file comparator and merge tool.
acl_set_fd Tru64 Sets the ACL on the file or directory designated by the file descriptor
rename Tru64 Rename a directory or a file within a file system
mkdir OpenBSD make a directory file
dirent FreeBSD directory file format
VOP_RMDIR FreeBSD remove a file or directory
mkdir FreeBSD make a directory file
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service