Diff of Linux commands

Source: Internet
Author: User

1. Command format:

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

2. Command function:

The diff command can compare individual files or directory contents. If you specify that the comparison is a file, it is only valid if the input is a text file. Compare the similarities and differences of text files in a row-by-line manner. If you specify a table of contents, 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:

-Specify 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 will only compare text files line by row.

-B or--ignore-space-change do 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.

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

-D or ifdef the output format of this parameter is available for the predecessor Processor macro.

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

The-f or-forward-ed output is formatted like an ED script file, but is displayed differently in the order of the original files.

-h or--speed-large-files can speed up when comparing large files.

-L or--ignore-matching-lines if two files are different in a few lines, and these lines both 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 for differences in case.

-L or--paginate the results to the PR program for paging.

-N or--rcs displays the comparison results in RCS format.

-N or--new-file when comparing directories, if file a only appears in a directory, the preset will display: Only in directory: file A If you use the-n parameter, diff will compare file A with a blank file.

-P If the file is compared to a C language code file, the name of the function where the difference is displayed.

-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 display only if there is no difference, no detailed information is displayed.

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

-S or--report-identical-files if no differences are found, the message is still displayed.

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

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

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

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

-V or--version displays version information.

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

-W or--width specifies the column width when using the-y parameter.

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

-X or--exclude-from you can save the file or directory type as a text file, and then specify the 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 using the-y parameter, if the contents of one row of two files are the same, the contents of that row are displayed only in the field on the left.

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

Summary:diff is generally used to compare the contents of two different files, such as diff file1 File2. So how do you figure out what's new in file1 or relative file2?

1> diff 1.txt 2.txt-y w > 3.txt

-Y is a side-by-side display of the similarities and differences of the file,-W is the specified column width

2> grep-e ' <|\| ' 3.txt

< in diff, what's new in file1 relative to File2

| In diff, it's the modified content.

When we use the grep command here, we use the escape character ' \ '.

Reference article: http://www.cnblogs.com/peida/archive/2012/12/12/2814048.html

Diff of Linux commands

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.