NAME
     diff - show differences between two text files

SYNOPSIS diff [-cefhn] [-bitw] old_file new_file diff [-D string] [-biw] old_file new_file diff [-l] [-r] [-s] [-cefhn] [-bitw] old_directory new_directory

DESCRIPTION The diff command is a differential file comparator. It compares pairs of text files and outputs the differences between them. If one of the argu- ments is a directory and the other is a file diff will look for a file of the same name as the file in the specified directory (e.g., diff x.c /tmp will compare ./x.c and /tmp/x.c).

If both arguments are directories the regular diff is run on all common files. In addition, binary files which differ, common subdirectories, and files which appear in only one directory are listed. The -r option can be used to recursively compare all the subdirectories.

There are five basic output formats: normal, context, ed script, forward ed script, and RCS-style. For the following examples assume we have two files, an old file called old that contains:

this line will change this line will stay the same this line will be deleted this line will stay the same

and a a new file called new that contains:

this line has changed this line will stay the same this line will stay the same this line was added

Each of the output format options is detailed below:

normal The normal format contains lines like:

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

Followed by the text in each file that changed. Lines from the first file are flagged with less-than and lines from the second file are flagged with greater-than. For example, a diff of the two sample files will produce:

1c1 < this line will change --- > this line has changed 3d2 < this line will be deleted 4a4 > this line was added

This resembles ed(1) commands to covert the first file into the second file. The numbers after the command letters refer to the second file. If a pair of numbers are the same they are abbreviated to to a single number (like in the example

above instead of 4a4,4 you just get 4a4).

context The context format produces a listing of differences with 3 lines of context on either side of the changes. Output be- gins with identification of the files involved and their mod- ification dates, then each change is separated by a short line of asterisks. The lines removed from the first file are marked with `- '; those added to the second file are marked `+ '. Lines which are changed from one file to the other are marked in both files with `! '. For our example:

*** old_file Mon Mar 1 14:59:43 1993 --- new_file Mon Mar 1 15:00:19 1993 *************** *** 1,4 **** ! this line will change this line will stay the same - this line will be deleted this line will stay the same --- 1,4 ---- ! this line has changed this line will stay the same this line will stay the same + this line was added

This is the recommended output format for distributing source diffs for use with the patch(1) program.

ed script Uses ed(1) commands to convert the first file into the second one. For our example:

4a this line was added 3d 1c this line has changed

forward ed Uses ed style commands but in the RCS-style order. For our example:

c1 this line has changed d3 a4 this line was added

RCS-style Outputs RCS-style forward diffs. For our example:

d1 1 a1 1 this line has changed d3 1 a4 1 this line was added

Exit status is 0 for no differences, 1 for some differences, 2 for trou- ble.

Choose zero or one of the following options:

-c Output context format diffs.

-e Output ed script format diffs. When comparing directories the output is a sh(1) script for converting the files common in the

two directories from the first directory to the second directory.

-f Output forward ed script format diffs. This output cannot be used with ed(1).

-n Output RCS-style format diffs.

-h Chunk input for faster processing. This works best when changes are short and separated. Will work on files of unlimited length.

The following options are available:

-b Ignore differences in trailing whitespace.

-i Ignore differences in case.

-t Expand tabs in output. Not available with the second form.

-w Ignore all differences in whitespace.

Options for the second form of diff are as follows:

-D string Merge the pair of files using the C preprocessor #ifdef. Compi- lation without defining string will yield old_file, while defin- ing string will yield new_file.

Options available when comparing directories are:

-l Each diff is piped through pr(1) to paginate it, other differ- ences are summarized at the end.

-r Recursively diff common subdirectories.

-s Print a message if the files are the same, by default they are not mentioned.

SEE ALSO cmp(1), comm(1), ed(1), patch(1), pr(1), sh(1)

BUGS The output from the -e and -f options is naive about creating lines con- sisting of a single period.

The -D option ignores existing preprocessor controls in the source files, and can generate overlapping #ifdef's.

Check out the Unix Man pages Manuals
Hosted by www.Geocities.ws

1