three different formats for diff in Unix systems

Source: Internet
Author: User
Tags diff
three different formats for diff in Unix systems
The diff command is a commonly used command in a UNIX system that compares the differences between two text files.
The current diff output is available in three different formats, respectively: normal format (regular diff)Contextual format (context diff)merge Format (Unified diff)
1. Normal format
command format:
diff < filename prior to change > < filename >
For Example:Create two files File1.txt and File2.txt, the contents are as follows: What is your name?
The My name is Lilei.
What is your name?
The My name is Hanmeimei.
Use diff command to compare two files differently: diff file1.txt File2.txt
The results are as follows:
Note:First line: 2C2 the previous 2 indicates that the 2nd row of the file1.txt has changed, C represents the change in mode (change), in addition to the change mode A (addition), d delete (deletion) The second line: < my name is Lilei. < means deleted from the File1.txt file, followed by the content to be deleted.    Third line:---to split file1.txt and File2.txt line fourth: > My name is Hanmeimei. > means added to File2.txt file, followed by added content.
2. Context Format
command FormatDiff-c < filename prior to change > < filename >
For Example:Diff-c file1.txt File2.txt
The results are as follows:
Note:The first line: * * * file1.txt 2018-04-20 10:08:51.338188679 +0800 second line:---file2.txt 2018-04-20 10:09:41.387461602 + 0800 above two lines show two The basic information, filename and time of the file, where "* *" indicates the file before the change, "---" indicates the file after the change
Third line: *************** This row is a split line
Line FOUR: * * * * 1,2 * * * * Fifth line: What is your name? Line SIX:! The My name is Lilei. The above three lines indicate that the file1.txt file has two lines of content, from 1-2, as shown in line fifth to sixth. There is an identifier in front of each line of the contents of the file, and Null indicates no change. Indicates that there is a change,-the expression is deleted, + the expression is added
Line Seventh:---1,2----line eighth: What is your name? Line Nineth:! The My name is Hanmeimei. Above three lines indicate the same meaning as above, for file2.txt files
3. Combined Format
command FormatDiff-u < filename prior to change > < filename >
For Example:Diff-u file1.txt File2.txt
The results are as follows:
Note:First line:---file1.txt 2018-04-20 10:08:51.338188679 +0800 second line: +++ file2.txt 2018-04-20 10:09:41.387461602 + 0800 above two lines show Basic information, filename, and time of two files, where "---" indicates the file before the change, "+++" indicates the file after the change
Third line: @@ -1,2 +1,2 @@ -1,2 Fourth: What is your name? Line five:-my name is Lilei. Line Six: +my name is Hanmeimei. The above four lines are actually similar to what the context format displays, except that the contents of the separately displayed file are merged together to show it, which is simpler. For two files the same content is displayed only once, and different content is displayed separately. -1,2 means that File1.txt has two lines of content, +1,2 means that File2.txt has two lines of content to display the content part, each line also has an identifier at the front, empty represents no change,-indicates deletion, + indicates an increase
add: The diff in git command is in the form of a merged UNIX format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.