Go to main content

man pages section 1: User Commands

Exit Print View

Updated: Wednesday, February 9, 2022



diff3 - 3-way differential file comparison


diff3 [-exEX3] filename1 filename2 filename3


diff3 compares three versions of a file. It publishes disagreeing ranges of text flagged with the following codes:


all three files differ


filename1 is different


filename2 is different


filename3 is different

The type of change suffered in converting a given range of a given file to some other is indicated in one of the following ways:

f : n1 a

Text is to be appended after line number n1 in file f, where f = 1, 2, or 3.

f : n1 , n2 c

Text is to be changed in the range line n1 to line n2. If n1 = n2, the range can be abbreviated to n1.

The original contents of the range follows immediately after a c indication. When the contents of two files are identical, the contents of the lower-numbered file is suppressed.

The following command applies the resulting script to filename1.

(cat script; echo ´1,$p´) | ed − filename1


The following options are supported:


Produce a script for the ed(1) editor that incorporates into filename1 all changes between filename2 and filename3 (that is, the changes that normally would be flagged ==== and ====3).

Text lines that consist of a single dot (.) defeat the –e option.


Produce a script that incorporates all changes between filename2 and filename3, but treat overlapping changes (that is, changes that would be flagged with ==== in the normal listing) differently. The overlapping lines from both files are inserted by the edit script, bracketed by <<<<<< and >>>>>> lines.


Produce a script to incorporate only changes flagged ====.


Produce a script that incorporates only changes flagged ====, but treat these changes in the manner of the –E option.


Produce a script to incorporate only changes flagged ====3.




Exit Status

The following exit values are returned:


Successful completion.


An error occurred. A difference was found or there was a fatal error.

> 1

A fatal error occurred.

Return values do not work the same as diff(1) or other vendor's versions of diff3.


See attributes(7) for descriptions of the following attributes:


See Also

diff(1), diff3(1g), attributes(7)


Files longer than 64 Kbytes do not work.