Diff is a Unix program line by line or section by section contrasts the differences between two text files each other.
Diff is a basic command-line function of a Unix system. A wide range of computer programs make full advantage of this. The output of the program is done in writing and is often also referred to as diff ( file extension. Diff ). The output format allows for machine processing.
Applications in version management are many and varied, the output of diff can be used for example as input to the Unix patch program to carry out the changes that has found diff to another text file. In addition, there are a number of programs, which represent the output of diff differences in a clear graphical form. In addition, diff is the basis of all merge functions.
The first versions of the program have been programmed to compare text files. Since 1980, however, support diff binary files.
Diff is run on the command line with the name of two text files as parameters:
$ Diff telefonliste2007.txt telefonliste2008.txt The two text files are compared line by line, that is, even if a line is different in the two files into a single character, interpreted this as a diff deleted and a newly inserted row.
The following two files are compared with diff.
Mayer, Susanne, bearings, -212 Schmid, Carola, management, -435 Schmidt, Eberhard, sales, -479 Schmitt, Marie, laboratory, -804 telefonliste2008.txt: Mayer, Susanne, bearings, -212 Schmid, Carola, management, -435 Schmitt, Marie, laboratory, -804 Waldmann, Serious, laboratory, -805 Zundel, Walter, sales, -476 The diff output looks like this:
3d2 < Schmidt, Eberhard, sales, -479 4a4, 5 > Waldmann, Serious, laboratory, -805 > Zundel, Walter, sales, -476 There are various output formats. The above example corresponds to the normal output (normal diff ) without any options. The lines beginning with a sharp, opening parenthesis, are present only in the first file, those that begin with a sharp, closing parenthesis, are present only in the second file. Lines that are the same in both files are not output. The individual blocks are separated by so called change commands ( " change orders ") that specify what action ( add rows - a change - c or Remove - d ) should be where lines run.
The so-called unified format ( unified diff ) is obtained by the -u option. In this case, each row that is found only in the first file, marked with a minus sign, and each row that is found only in the second file, with a plus sign. The two files common lines are characterized by a space.
Are typically not all rows but only the blocks of rows are in the vicinity of a difference. At the beginning of the output are two lines that are marked with three minus three plus signs, respectively. To view the files on which the diff applies. Each block is preceded by a line of at sign ( @ ) is surrounded. This indicates which lines in the corresponding block starts in both files and, separated by a comma, as long he is in the respective file.
In the above example results in unified diff format
--- Telefonliste2007.txt 2007-12-28 13:12:34.000000000 0100 2008-07-28 14:16:26.000000000 0100 telefonliste2008.txt @ @ -1,4 1,5 @ @ Mayer, Susanne, bearings, -212 Schmid, Carola, management, -435 Schmidt, Eberhard, sales, -479 Schmitt, Marie, laboratory, -804 Waldmann, Serious, laboratory, -805 Zundel, Walter, sales, -476 history
The diff program was developed in the early 1970s on the Unix operating system from AT & T Bell Labs in Murray Hill, New Jersey, United States. The final version, which belonged to this very early Unix system was written entirely by Douglas McIlroy. These studies were published in 1976 in a document, which was co-authored by James W. Hunt, who also wrote one of the initial versions of diff.
McIlroy work was influenced by Steve Johnson's comparison program on gecos and Mike Lesks proof program, which has emerged as diff on Unix. Proof produced line - by-line changes as diff and used for angle brackets (">" and "< ") to row inserts and row distances in the output of the program display. The heuristic method that used these programs was considered unreliable. The potential usefulness of a diff tools inspired McIlroy to develop a new, more robust program that had many uses, but still delivered a good performance in the processor and memory limits of the PDP -11 hardware. Its success was a result of collaboration with the people of Bell Labs, including Alfred V. Aho, Elliot Pinson, Jeffrey Ullman and Harold S. Stone.
Free software implementations
The GNU project provides an implementation of diff ( and diff3, which compares three files ) in the package.
Several tools that run on different platforms, based on the diffutils engine of the GNU project and provide a graphical frontend for the same information dar. Some of these programs can also edit and merge files.
- Kompare - a graphical interface for diff
- Meld - very comprehensive graphical interface for diff
- WinMerge - an open source diff for Windows
- Patch - diff to the counterpart, can be reconstructed with the files based on their differences.
- Delta encoding - a data compression method, in which case similar files only the differences to the output file will be stored, for example in version control.