Linux Base command (+) diff command

Source: Internet
Author: User
Tags comparison diff versions

The diff command is a very important tool on Linux to compare the contents of a file, especially to compare two different versions of a file to find where it was changed. Diff prints changes to each row on the command line. The latest version of diff also supports binary files. The diff program's output is called a patch (patch) because there is also a patch program in the Linux system that updates the A.C file contents to B.C according to the diff output. Diff is an integral part of the version control tools such as SVN, CVS, and Git.

1. Command format:

diff[parameters] [file 1 or directory 1][file 2 or directory 2]

2. Command function:

diff commands can compare individual files or directory contents. If you specify a file for comparison, it is only valid when entered as a text file. Compare the similarities and differences of text files in a row-by-line manner. If you specify a catalog, the diff command compares a text file with the same name in two directories. Lists the different binaries, common subdirectories, and files that appear only in one directory.

3. Command parameters:

-Specifies how many lines of text to display. This parameter must be used in conjunction with the-C or-u parameter.

The-A or--text diff preset only compares text files on a line-by-row basis.

-B or--ignore-space-change does not check for differences in whitespace characters.

-B or--ignore-blank-lines does not check for blank lines.

-C Displays all the text and marks the difference.

-C or--context is the same as executing the "-c-" directive.

The-D or--minimal uses different algorithms to compare in smaller units.

-D or ifdef the output format of this parameter can be used for the predecessor processor macros.

The output format of the-E or--ed This parameter is available for the ed script file.

The-f or-forward-ed output formats resemble Ed's script files, but display the differences in the order of the original files.

When-h or--speed-large-files compare large files, you can speed up.

-L or--ignore-matching-lines if two files are different in a few lines, and these lines contain the characters or strings specified in the option, the differences between the two files are not displayed.

-I or--ignore-case do not check case differences.

-L or--paginate the results to the PR program to page.

-N or--rcs displays the results of the comparison in the form of RCS.

-N or--new-file when comparing directories, if file a only appears in a directory, the preset will appear: Only in directory: file A If you use the-n argument, diff compares file A to a blank file.

-P Displays the name of the function that contains the difference if the file being compared is a C-language code file.

-P or--unidirectional-new-file is similar to-N, but this file is compared to a blank file only if the second directory contains a file that is not in the first directory.

-Q or--brief only shows no differences, and does not display detailed information.

-R or--recursive to compare files in subdirectories.

-S or--report-identical-files still displays the information if no differences are found.

-S or--starting-file when comparing directories, starting from the specified file.

-T or--expand-tabs expands the tab character when it is output.

-T or--initial-tab precede each line with the tab character to align.

-u,-u or--unified= displays the different contents of the file in a merged manner.

-V or-version displays versions information.

-W or--ignore-all-space ignores all whitespace characters.

-W or--width specifies the column width when the-y parameter is used.

-X or--exclude does not compare the files or directories specified in the options.

-X or--exclude-from you can save a file or directory type as a text file, and then specify this text file in =.

-Y or--side-by-side displays the similarities and differences of the files in a parallel manner.

--help display Help.

--left-column When you use the-y parameter, if the contents of one row of two files are the same, the row content is displayed only in the field on the left.

--suppress-common-lines displays only the differences when using the-y parameter.

4. Use instance:

Example 1: Comparing two files

Command:

Output:

[Root@localhost test3]# diff Log2014.log Log2013.log

3c3

< 2014-03

---

> 2013-03

8c8

< 2013-07

---

> 2013-08

11,12d10

< 2013-11

< 2013-12

Description

The above "3c3" and "8c8" indicate that Log2014.log and log20143log files are different in line 3 and row 8th, and "11,12D10" indicates that the first file has more than 11th and 12 lines than the second file.

Diff's Normal display format has three tips:

A-add

C-change

D-delete

Related Article

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.