Linux command-diff

Source: Internet
Author: User
Tags diff

Features of the 1>diff command
The function of the diff command in Linux is to compare two text files on a line-by-row basis, listing their differences. It checks the given file for a system and displays all the different rows in the two files without requiring the file to be sorted beforehand.

2> syntax
diff [Options] file1 file2

The command tells the user which rows to modify in order to make the two files File1 and file2 consistent. If File1 or file2 is represented by "-", the standard input is indicated. If File1 or file2 is a directory, diff will use a file of the same name in that directory for comparison.

3>[options] Main parameters

-A: treats all files as text files.

-B or –ignore-space-change ignores the difference caused by whitespace.

-B or –ignore-blank-lines ignores the difference caused by empty rows.

-C: Use the schema output format.

-H: Use heuristics to accelerate searches of large files.

-I: Ignores case changes.

-N–RCS: Output RCS format.

-N or –new-file when the directory is compared, if file a only appears in a directory, it will display: only in the directory; If file a uses the-n parameter, diff will compare file A to a blank file.

-R or –recursive to compare files in subdirectories.

-u,-u< number of columns > or –unified=< columns > displays the contents of the file differently in a merged manner.

Example description of 4> usage method

Example: Diff/usr/xu mine

Compare the file named mine in the directory/usr/xu with the mine file in the current directory.

Typically the output is made up of lines in the following form:

N1 a N3,n4

N1,n2 D N3

N1,N2 C N3,N4 These lines like the ed command to convert Filel into file2. The line numbers (N1,N2) before the letters (a, D, and C) are for file1, and the following line numbers (N3,N4) are for file2. The letters A, D, and C represent additional, delete, and modify actions, respectively.

Following each row in the above form follows a number of rows affected, the line beginning with "<" belongs to the first file, and the line preceded by ">" belongs to the second file.

Diff can distinguish between block and character device files and FIFO (pipeline files), and does not compare them to normal files.

If both File1 and file2 are directories, diff generates a lot of information.

5>diff most commonly used features

Diff has a lot of features that we don't usually use, and the most common feature is the ability to generate patch files:

Diff-urn old/new/> Mysoft.patch
The parameter-u means using the unified format,-R for the comparison directory, and-N to treat the nonexistent file as an empty file, so that the newly added file will also appear in the patch file.

Then use the following commands where you need to apply patches:

Patch-p0 < Mysoft.patch

The-y command of diff (long format –side-by-side) divides the screen into the left and right sections to compare the differences between the two files. Many graphical comparison tools have this functionality, but this is useful if you can use only the command line. If you want to change the width of the left and right parts, you can specify them by the-W (–width) parameter.
The –ignore-blank-lines parameter can not check for blank lines. In this case, the DOS format and UNIX-formatted files are compared to each other, so there is not a large number of differences because of inconsistent line breaks.

Linux command-diff

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.