diff(differential)
diff(differential)功能说明:比较文件的差异。
语 法:diff [-abBcdefHilnNpPqrstTuvwy][-<行数>][-C <行数>][-D <巨集名称>][-I <字符或字符串>][-S <文件>][-W <宽度>][-x <文件或目录>][-X <文件>][--help][--left-column][--suppress-common-line][文件或目录1][文件或目录2]
补充说明:diff以逐行的方式,比较文本文件的异同处。所是指定要比较目录,则diff会比较目录中相同文件名的文件,但不会比较其中子目录。
参 数:
-<行数> 指定要显示多少行的文本。此参数必须与-c或-u参数一并使用。
-a或--text diff预设只会逐行比较文本文件。
-b或--ignore-space-change 不检查空格字符的不同。
-B或--ignore-blank-lines 不检查空白行。
-c 显示全部内文,并标出不同之处。
-C<行数>或--context<行数> 与执行"-c-<行数>"指令相同。
-d或--minimal 使用不同的演算法,以较小的单位来做比较。
-D<巨集名称>或ifdef<巨集名称> 此参数的输出格式可用于前置处理器巨集。
-e或--ed 此参数的输出格式可用于ed的script文件。
-f或-forward-ed 输出的格式类似ed的script文件,但按照原来文件的顺序来显示不同处。
-H或--speed-large-files 比较大文件时,可加快速度。
-l<字符或字符串>或--ignore-matching-lines<字符或字符串> 若两个文件在某几行有所不同,而这几行同时都包含了选项中指定的字符或字符串,则不显示这两个文件的差异。
-i或--ignore-case 不检查大小写的不同。
-l或--paginate 将结果交由pr程序来分页。
-n或--rcs 将比较结果以RCS的格式来显示。
-N或--new-file 在比较目录时,若文件A仅出现在某个目录中,预设会显示:
Only in目录:文件A若使用-N参数,则diff会将文件A与一个空白的文件比较。
-p 若比较的文件为C语言的程序码文件时,显示差异所在的函数名称。
-P或--unidirectional-new-file 与-N类似,但只有当第二个目录包含了一个第一个目录所没有的文件时,才会将这个文件与空白的文件做比较。
-q或--brief 仅显示有无差异,不显示详细的信息。
-r或--recursive 比较子目录中的文件。
-s或--report-identical-files 若没有发现任何差异,仍然显示信息。
-S<文件>或--starting-file<文件> 在比较目录时,从指定的文件开始比较。
-t或--expand-tabs 在输出时,将tab字符展开。
-T或--initial-tab 在每行前面加上tab字符以便对齐。
-u,-U<列数>或--unified=<列数> 以合并的方式来显示文件内容的不同。
-v或--version 显示版本信息。
-w或--ignore-all-space 忽略全部的空格字符。
-W<宽度>或--width<宽度> 在使用-y参数时,指定栏宽。
-x<文件名或目录>或--exclude<文件名或目录> 不比较选项中所指定的文件或目录。
-X<文件>或--exclude-from<文件> 您可以将文件或目录类型存成文本文件,然后在=<文件>中指定此文本文件。
-y或--side-by-side 以并列的方式显示文件的异同之处。
--help 显示帮助。
--left-column 在使用-y参数时,若两个文件某一行内容相同,则仅在左侧的栏位显示该行内容。
--suppress-common-lines 在使用-y参数时,仅显示不同之处。
diff
diff
Compare two text files. diff reports lines that differ between file1 and file2. Output consists of lines of context from each file, with file1 text flagged by a < symbol and file2 text by a > symbol. Context lines are preceded by the ed command (a, c, or d) that would be used to convert file1 to file2. If one of the files is -, standard input is read. If one of the files is a directory, diff locates the filename in that directory corresponding to the other argument (e.g., diff my_dir junk is the same as diff my_dir/junk junk). If both arguments are directories, diff reports lines that differ between all pairs of files having equivalent names (e.g., olddir/program and newdir/program); in addition, diff lists filenames unique to one directory, as well as subdirectories common to both. See also cmp.
Options
Treat all files as text files. Useful for checking to see if binary files are identical.
Ignore repeating blanks and end-of-line blanks; treat successive blanks as one.
Ignore blank lines in files.
Context diff: print 3 lines surrounding each changed line.
Context diff: print n lines surrounding each changed line. The default context is 3 lines.
To speed up comparison, ignore segments of numerous changes and output a smaller set of changes.
When handling C files, create an output file that contains all the contents of both input files, including #ifdef and #ifndef directives that reflect the directives in both files.
Produce a script of commands (a, c, d) to re-create file2 from file1 using the ed editor.
For context and unified diff, show the most recent line containing regexp before each block of changed lines.
Speed output of large files by scanning for scattered small changes; long stretches with many changes may not show up.
Print brief usage message.
In an attempt to find a more compact listing, keep n lines on both sides of the changed lines when performing the comparison.
Ignore case in text comparison. Uppercase and lowercase are considered the same.
Ignore lines in files that match the regular expression regexp.
Paginate output by passing it to pr.
For context and unified diff, print label in place of the filename being compared. The first such option applies to the first filename and the second option to the second filename.
For two-column output (-y), show only left column of common lines.
Produce output in RCS diff format.
Treat nonexistent files as empty.
When handling files in C or C-like languages such as Java, show the function containing each block of changed lines. Assumes -c, but can also be used with a unified diff.
If two directories are being compared and the first lacks a file that is in the second, pretend that an empty file of that name exists in the first directory.
Output only whether files differ.
Compare subdirectories recursively.
Indicate when files do not differ.
For directory comparisons, begin with the file filename, skipping files that come earlier in the standard list order.
For two-column output (-y), do not show common lines.
Produce output with tabs expanded to spaces.
Insert initial tabs into output to line up tabs properly.
Unified diff: print old and new versions of lines in a single block, with 3 lines surrounding each block of changed lines.
Unified diff: print old and new versions of lines in a single block, with n lines surrounding each block of changed lines. The default context is 3 lines.
Print version number of this version of diff.
Ignore all whitespace in files for comparisons.
For two-column output (-y), produce columns with a maximum width of n characters. Default is 130.
Do not compare files in a directory whose names match regexp.
Do not compare files in a directory whose names match patterns described in the file filename.
Produce two-column output.
For context and unified diff, print n lines of context. Same as specifying a number with -C or -U.