diff command explanation

Source: Internet
Author: User

diff Command parameters:
diff-Find out the different points of two files
General overview
diff [Options] source file destination file
Below is a summary of all the options that GNU accepts for diff. Most of the options have two identical names, one is a single followed by the letter, and the other is by-the long name of the derivation. Multiple single-letter options (unless they produce ambiguity) can be combined into a single line of command-line syntax-ac is equivalent to-a-c. Long named options can be shortened to any unique prefix of their name. option to display ambiguous options with ([and])
-Number of rows (an integer)
Displays the number of context rows (an integer). This option does not specify the output format itself, which is not effective unless used in combination with-C or-U. This is an option that has been abandoned, and the context must have at least two lines for the correct operation.
-A
All files are treated as text files to be compared on a line-by-row basis, even if they seem not to be text files.
-B
Ignores changes caused by spaces.
-B
Ignores the change caused by inserting a blank line.
–brief
Only report whether the files are different and care about the details of the differences.
-C
Use the context output format.
-C line number (an integer)

–context[=lines]
Use the context output format to display the specified number of rows (an integer), or propelled (when the number of rows is not given. For the correct operation, the context must have at least two rows.
–changed-group-format=format
Use format to output a set of rows that contain two different files, in the format If-then-else.
-D
The change algorithm may find a smaller set of changes. This makes the diff slow (sometimes slower).
-D Name
Merges the If-then-else format output, preprocessing the macro (provided by the name parameter) condition.
-E

The

–ed
Output is a valid ed script.
–exclude=pattern
When comparing directories, ignores and matches the pattern (style) in the table of contents.
–exclude-from=file
Compares directories, ignoring files and directories in the directory that match any style contained in file.
–expand-tabs
Expands tab space at output to protect the tab alignment of the input file
-F
produces an output that is much like the Ed script, but has changed in the order in which they appear in the file
-F regexp
In context and uniform format, the matching regexp is displayed for each chunk. Some of the preceding lines.
–forward-ed
produces output like an ED script, but they change in the order in which the files appear. The
-H
Option now has no effect, and it renders UNIX compatibility.
-H
uses heuristic rules to speed up the operation of large files that have many discrete small differences.
–horizon-lines=lines
compares the last line with a common prefix for a given number of rows, and has a common or prefixed forward.
-I
ignores case.
-I regexp
ignores the changes that are caused by inserting, deleting rows (provided by the regexp parameter).
–ifdef=name
Merges the If-then-else format output, preprocessing the macro (provided by the name parameter) condition.
–ignore-all-space
ignores whitespace when comparing rows.
–ignore-blank-lines
ignores inserting and deleting empty rows
–ignore-case
ignores case.
–ignore-matching-lines=regexp
Ignores insert delete rows (referenced by the regexp parameter).
–ignore-space-change
ignores the number of blanks.
–initial-tab
Prints the tab instead of a space before a line of text, whether it is a regular or formatted contextual relationship. The cause is that the tab alignment looks as if it were regular.
-L
produces a PR-encoded output.
-L Label

–label=label
Use the label-given character in the file header instead of the filename output.
–left-column
Print the left side of two public rows in a parallel manner
–line-format=format
Use format to output all the rows in the If-then-else format.
–minimal
The change algorithm may find a smaller set of changes. This makes the diff slow (sometimes slower).
-N
Output rc-format diffs; The number of rows specified in each instruction is affected by the same as-F.
-N

–new-file
In a directory comparison, if that file is found only in one of the directories, it is considered to be an empty file in another directory.
–new-group-format=format
Use format to output a row group that is only fetched in the second file in if-then-else format
–new-line-format=format
Use format to output only one row in the second file in if-then-else format
–old-group-format=format
Use format to output a row group that is only fetched in the first file in if-then-else format
–old-line-format=format
Use format to output only one row taken in the first file using format in if-then-else format
-P
Shows a change with a C function.
-P
In a directory comparison, if that file is found only in one of the directories, it is considered to be an empty file in another directory.
–paginate
Generate a PR-encoded output.
-Q
Report only if the files are different and do not report detailed differences.
-R
When comparing directories, recursively compares any subdirectories that are found.
–rcs
Output rc-format diffs; The number of rows specified in each instruction is affected by the same as-F.
–recursive
When comparing directories, recursively compares any subdirectories that are found.
–report-identical-files

-S
reports the same two files.
-S file
is started by file when comparing directories. This is used to continue the interrupted comparison.
–sdiff-merge-assist
Prints additional information to help Sdiff. Sdiff Use these options when running diff. These options are not intended for direct use by users.
–show-c-function
shows a change with a C function.
–show-function-line=regexp
in context and in a uniform format, for each chunk of the difference, shows that some of the preceding lines of the regexp.
–side-by-side
Use a side-by-side output format.
–speed-large-files
uses heuristic rules to speed up the operation of large files that have many discrete small differences.
–starting-file=file
When the catalog is compared, it is started by file. This is used to continue the interrupted comparison.
–suppress-common-lines
does not print public rows in a parallel format.
-T
expands tab space at output to protect the tab alignment of the input file
-t
Prints the tab instead of a space before a line of text, whether it is a regular or formatted contextual relationship. The cause is that the tab alignment looks as if it were regular.
–text
All of the files are treated as text files to be compared on a line-by-row basis, even if they are not text files.
-U
uses a uniform output format.
–unchanged-group-format=format
uses format to output a common row group of two files in the format of If-then-else.
–unchanged-line-format=format
uses format to output a public row of two files in the format If-then-else.
–unidirectional-new-file
In a directory comparison, if that file is found only in one of the directories, it is considered to be an empty file in another directory.
-U lines

–unified[=lines]
Use the output of the pre-and post-relational format to display the specified number of rows (an integer), or propelled (when the number of rows is not given. For the correct operation, the context must have at least two rows.
-V

–version
The output diff version number.
-W
Ignore spaces when comparing rows
-W Columns

–width=columns
When the output is in a parallel format, the specified column width is used.
-X pattern
When comparing directories, ignore and match the pattern (style) in the table of contents.
-X File
When comparing directories, ignore files and directories in the directory that match any style contained in file.
-Y
Output using a parallel format

Instance:

There are two of these files:
Program Listing 1:HELLO.C

Include

int main (void)
{
Char msg[] = "Hello world!";

puts(msg);printf("Welcome to use diff commond.\n");return 0;    

}
Program Listing 2:HELLO_DIFF.C

Includeinclude

int main (void)
{
Char msg[] = "Hello world,fome hello_diff.c";

puts(msg);printf("hello_diff.c says,‘Here you are,using diff.‘\n");return 0;    

}
We use the diff command to see the differences between the two files, and there are several handy ways to do it:
1. Normal format output:
[Email protected] diff]# diff hello.c Hello_diff.c
1a2

include

5c6
Char msg[] = "Hello world,fome hello_diff.c";
8c9
printf ("Hello_diff.c says, ' Here ' are,using diff. ' \ n ');
[Email protected] diff]#
The "1a2" above indicates that one of the following files "HELLO_DIFF.C" is more than the previous file "hello.c" a row
"5c6" indicates that line 5th of the first file differs from line 6th of the second file
2. Side-by format output
[[Email protected] diff]# diff hello.c Hello_diff.c-y-w 130

Include #include
                                                          

int main (void) int main (void)
{ {
Char msg[] = "Hello world!"; | Char msg[] = "Hello world,fome hello_diff.c";
Puts (msg); Puts (msg);
printf ("Welcome to use diff commond.\n"); | printf ("Hello_diff.c says, ' Here's are,using diff. ')
return 0; return 0;
} }
[Email protected] diff]#
The contrast of this side format is straightforward and can be quickly found in different places.
-W Select to specify the width of the output column, which specifies that the output width is 130
3. Context output format
[Email protected] diff]# diff hello.c Hello_diff.c-c
* hello.c 2007-09-25 17:54:51.000000000 +0800
-HELLO_DIFF.C 2007-09-25 17:56:00.000000000 +0800

* 1,11 * *
#include

int main (void)
{
! Char msg[] = "Hello world!";

    puts(msg);

! printf ("Welcome to use diff commond.\n");

    return 0;

}
-1,12--
#include
+ #include

int main (void)
{
! Char msg[] = "Hello world,fome hello_diff.c";

    puts(msg);

! printf ("Hello_diff.c says, ' Here ' are,using diff. ' \ n ');

    return 0;

}
[Email protected] diff]#
In this way, a description of the comparison file is made in the first two lines, here are three special characters:
+ Compare files with the latter more than the previous line
-Compare the latter of the file with less than the previous line
! Compare a file with a different line
4. Unified output Format
[Email protected] diff]# diff hello.c Hello_diff.c-u
-HELLO.C 2007-09-25 17:54:51.000000000 +0800
+ + + HELLO_DIFF.C 2007-09-25 17:56:00.000000000 +0800
@@ -1,11 +1,12 @@

Include

+ #include

int main (void)
{
-char msg[] = "Hello world!";
+ char msg[] = "Hello world,fome hello_diff.c";

    puts(msg);

-printf ("Welcome to use diff commond.\n");
+ printf ("Hello_diff.c says, ' Here ' are,using diff. ' \ n ');

    return 0;

}
[Email protected] diff]#
As you can see, the output of the unified format is more compact, so it's easier to understand and easier to modify.
5. Other
If you want to see whether the two files are different and don't want to show the difference, you can add the-Q option:
[Email protected] diff]# diff hello.c Hello_diff.c-q
Files hello.c and HELLO_DIFF.C differ
[[email protected] diff]# In addition you can provide some matching rules to ignore a difference, you can use-I regexp
[Email protected] diff]# diff hello.c Hello_diff.c-c-I include
* hello.c 2007-09-25 17:54:51.000000000 +0800
-HELLO_DIFF.C 2007-09-25 17:56:00.000000000 +0800

* 2,11 * *

int main (void)
{
! Char msg[] = "Hello world!";

    puts(msg);

! printf ("Welcome to use diff commond.\n");

    return 0;

}
-3,12--

int main (void)
{
! Char msg[] = "Hello world,fome hello_diff.c";

    puts(msg);

! printf ("Hello_diff.c says, ' Here ' are,using diff. ' \ n ');

    return 0;

}
[Email protected] diff]#
This is done with the "-I include" option to ignore lines with the word "include"

Part of the content from: http://blog.chinaunix.net/u1/48325/showart_433936.html
Http://hi.baidu.com/ilotus_y/blog/item/b94231d6f55a1e2a07088b91.html

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

diff command explanation

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.