diff 中文man页面

系统
在最简单的情况是, diff 比较两个文件的内容 (源文件 和 目标文件). 文件名可以是 - 由标准输入设备读入的文本. 作为特别的情况是, diff - - 比较一份标准输入的它自己的拷贝如果 源文件 是一个目录和 目标文件 不是(目录), diff 会比较在 源文件(目录) 里的文件的中和 目标文件同名的(文件), 反过来也一样. 非目录文件不能是 -. 如果 源文件 和 目标文件 都是目录, diff 比较两个目录中相应的文件,依照字母次序排序;这个比较是不会递归的,除非给出 -r 或者 --recursive. diff 不把一个目录的内容看为它是一个文件来比较。被指

名字

diff - 找出两个文件的不同点  

总览

diff [选项] 源文件 目标文件  

描述

在最简单的情况是, diff 比较两个文件的内容 (源文件目标文件). 文件名可以是 - 由标准输入设备读入的文本. 作为特别的情况是, diff - - 比较一份标准输入的它自己的拷贝如果 源文件 是一个目录和 目标文件 不是(目录), diff 会比较在 源文件(目录) 里的文件的中和 目标文件同名的(文件), 反过来也一样. 非目录文件不能是 -. 如果 源文件目标文件 都是目录, diff 比较两个目录中相应的文件,依照字母次序排序;这个比较是不会递归的,除非给出 -r 或者 --recursive. diff 不把一个目录的内容看为它是一个文件来比较。被指定的文件不能是标准的输入, 因为标准的输入是无名的并且"有一样的名字的文件"的观点不适用。 diff 的选项由 -, 开始所以正常地 源文件(名)目标文件(名) 不可以用 - 开头. 然而, -- 可以被它视为保留的即使作为文件名的开头( they begin with -.  

选项

下面是 GNU所接受的 diff 的所有选项的概要. 大多数的选项有两个相同的名字,一个是单个的跟在 - 后面字母, 另一个是由 -- 引出的长名字. 多个单字母选项(除非它们产生歧义)能够组合为单行的命令行语法 -ac 是等同于 -a -c. 长命名的选项能被缩短到他们的名字的任何唯一的前缀. 用 ([]) 括起来显示选项产生歧义的选项

-行数(一个整数)
显示上下文 行数 (一个整数). 这个选项自身没有指定输出格式,这是没有效果的,除非和 -c 或者 -u 组合使用. 这是已废置的选项,对于正确的操作, 上下文至少要有两行。
-a
所有的文件都视为文本文件来逐行比较,甚至他们似乎不是文本文件.
-b
忽略空格引起的变化.
-B
忽略插入删除空行引起的变化.
--brief
仅报告文件是否相异,在乎差别的细节.
-c
使用上下文输出格式.
-C 行数(一个整数)

--context[=lines]
使用上下文输出格式,显示以指定 行数 (一个整数), 或者是三行(当 行数 没有给出时. 对于正确的操作, 上下文至少要有两行.
--changed-group-format=format
使用 format 输出一组包含两个文件的不同处的行,其格式是 if-then-else .
-d
改变算法也许发现变化的一个更小的集合.这会使 diff 变慢 (有时更慢).
-D name
合并 if-then-else 格式输出, 预处理宏(由name参数提供)条件.
-e

--ed
输出为一个有效的 ed 脚本.
--exclude=pattern
比较目录的时候,忽略和目录中与 pattern(样式) 相配的.
--exclude-from=file
比较目录的时候,忽略和目录中与任何包含在 file(文件) 的样式相配的文件和目录.
--expand-tabs
在输出时扩展tab为空格,保护输入文件的tab对齐方式
-f
产生一个很象 ed 脚本的输出,但是但是在他们在文件出现的顺序有改变
-F regexp
在上下文和统一格式中,对于每一大块的不同,显示出匹配 regexp. 的一些前面的行.
--forward-ed
产生象 ed 脚本的输出,但是它们在文件出现的顺序有改变。
-h
这选项现在已没作用,它呈现Unix的兼容性.
-H
使用启发规则加速操作那些有许多离散的小差异的大文件.
--horizon-lines=lines
比较给定行数的有共同前缀的最后行,和有共同或缀的最前行.
-i
忽略大小写.
-I regexp
忽略由插入,删除行(由regexp 参数提供参考)带来的改变.
--ifdef=name
合并 if-then-else 格式输出, 预处理宏(由name参数提供)条件.
--ignore-all-space
在比较行的时候忽略空白.
--ignore-blank-lines
忽略插入和删除空行
--ignore-case
忽略大小写.
--ignore-matching-lines=regexp
忽略插入删除行(由regexp 参数提供参考).
--ignore-space-change
忽略空白的数量.
--initial-tab
在文本行(无论是常规的或者格式化的前后文关系)前输出tab代替空格. 引起的原因是tab对齐方式看上去象是常规的一样.
-l
产生通过 pr 编码的输出.
-L label

--label=label
使用 label 给出的字符在文件头代替文件名输出.
--left-column
以并列方式印出两公共行的左边
--line-format=format
使用 format 输出所有的行,在 if-then-else 格式中.
--minimal
改变算法也许发现变化的一个更小的集合.这会使 diff 变慢 (有时更慢).
-n
输出 RC-格式 diffs; 除了每条指令指定的行数受影响外 象 -f 一样。
-N

--new-file
在目录比较中,如果那个文件只在其中的一个目录中找到,那么它被视为在另一个目录中是一个空文件.
--new-group-format=format
使用 format 以if-then-else 格式输出只在第二个文件中取出的一个行组
--new-line-format=format
使用 format 以if-then-else 格式输出只在第二个文件中取出的一行
--old-group-format=format
使用 format 以if-then-else 格式输出只在第一个文件中取出的一个行组
--old-line-format=format
使用 format 使用 format 以if-then-else 格式输出只在第一个文件中取出的一行
-p
显示带有c函数的改变.
-P
在目录比较中,如果那个文件只在其中的一个目录中找到,那么它被视为在另一个目录中是一个空文件.
--paginate
产生通过 pr 编码的输出.
-q
仅报告文件是否相异,不报告详细的差异.
-r
当比较目录时,递归比较任何找到的子目录.
--rcs
输出 RC-格式 diffs; 除了每条指令指定的行数受影响外 象 -f 一样。
--recursive
当比较目录时,递归比较任何找到的子目录.
--report-identical-files

-s
报告两个文件相同.
-S file
当比较目录时,由 file 开始. 这用于继续中断了的比较.
--sdiff-merge-assist
打印附加的信息去帮助 sdiff. sdiff 在运行 diff 时使用这些选项. 这些选项不是特意为使用者直接使用而准备的。
--show-c-function
显示带有c函数的改变.
--show-function-line=regexp
在上下文和统一的格式,对于每一大块的差别,显示出匹配 regexp. 的一些前面的行
--side-by-side
使用并列的输出格式.
--speed-large-files
使用启发规则加速操作那些有许多离散的小差异的大文件.
--starting-file=file
当比较目录时,由 file 开始. 这用于继续中断了的比较.
--suppress-common-lines
在并列格式中不印出公共行。
-t
在输出时扩展tab为空格,保护输入文件的tab对齐方式
-T
在文本行(无论是常规的或者格式化的前后文关系)前输出tab代替空格.引起的原因是tab对齐方式看上去象是常规的一样.
--text
所有的文件都视为文本文件来逐行比较,甚至他们似乎不是文本文件.
-u
使用统一的输出格式.
--unchanged-group-format=format
使用 format 输出两个文件的公共行组,其格式是if-then-else.
--unchanged-line-format=format
使用 format 输出两个文件的公共行,其格式是if-then-else.
--unidirectional-new-file
在目录比较中,如果那个文件只在其中的一个目录中找到,那么它被视为在另一个目录中是一个空文件.
-U lines

--unified[=lines]
使用前后关系格式输出,显示以指定 行数 (一个整数), 或者是三行(当 行数 没有给出时. 对于正确的操作, 上下文至少要有两行.
-v

--version
输出 diff 版本号.
-w
在比较行时忽略空格
-W columns

--width=columns
在并列格式输出时,使用指定的列宽.
-x pattern
比较目录的时候,忽略和目录中与 pattern(样式) 相配的.
-X file
比较目录的时候,忽略和目录中与任何包含在 file(文件) 的样式相配的文件和目录.
-y
使用并列格式输出

参考

cmp(1), comm(1), diff3(1), ed(1), patch(1), pr(1), sdiff(1).  

#p#

NAME

diff - find differences between two files 

SYNOPSIS

diff [options] from-file to-file  

DESCRIPTION

In the simplest case, diff compares the contents of the two files from-file and to-file. A file name of - stands for text read from the standard input. As a special case, diff - - compares a copy of standard input to itself.

If from-file is a directory and to-file is not, diff compares the file in from-file whose file name is that of to-file, and vice versa. The non-directory file must not be -.

If both from-file and to-file are directories, diff compares corresponding files in both directories, in alphabetical order; this comparison is not recursive unless the -r or --recursive option is given. diff never compares the actual contents of a directory as if it were a file. The file that is fully specified may not be standard input, because standard input is nameless and the notion of ``file with the same name'' does not apply.

diff options begin with -, so normally from-file and to-file may not begin with -. However, -- as an argument by itself treats the remaining arguments as file names even if they begin with -.  

Options

Below is a summary of all of the options that GNU diff accepts. Most options have two equivalent names, one of which is a single letter preceded by -, and the other of which is a long name preceded by --. Multiple single letter options (unless they take an argument) can be combined into a single command line word: -ac is equivalent to -a -c. Long named options can be abbreviated to any unique prefix of their name. Brackets ([ and ]) indicate that an option takes an optional argument.

-lines
Show lines (an integer) lines of context. This option does not specify an output format by itself; it has no effect unless it is combined with -c or -u. This option is obsolete. For proper operation, patch typically needs at least two lines of context.
-a
Treat all files as text and compare them line-by-line, even if they do not seem to be text.
-b
Ignore changes in amount of white space.
-B
Ignore changes that just insert or delete blank lines.
--brief
Report only whether the files differ, not the details of the differences.
-c
Use the context output format.
-C lines

--context[=lines]
Use the context output format, showing lines (an integer) lines of context, or three if lines is not given. For proper operation, patch typically needs at least two lines of context.
--changed-group-format=format
Use format to output a line group containing differing lines from both files in if-then-else format.
-d
Change the algorithm to perhaps find a smaller set of changes. This makes diff slower (sometimes much slower).
-D name
Make merged if-then-else format output, conditional on the preprocessor macro name.
-e

--ed
Make output that is a valid ed script.
--exclude=pattern
When comparing directories, ignore files and subdirectories whose basenames match pattern.
--exclude-from=file
When comparing directories, ignore files and subdirectories whose basenames match any pattern contained in file.
--expand-tabs
Expand tabs to spaces in the output, to preserve the alignment of tabs in the input files.
-f
Make output that looks vaguely like an ed script but has changes in the order they appear in the file.
-F regexp
In context and unified format, for each hunk of differences, show some of the last preceding line that matches regexp.
--forward-ed
Make output that looks vaguely like an ed script but has changes in the order they appear in the file.
-h
This option currently has no effect; it is present for Unix compatibility.
-H
Use heuristics to speed handling of large files that have numerous scattered small changes.
--horizon-lines=lines
Do not discard the last lines lines of the common prefix and the first lines lines of the common suffix.
-i
Ignore changes in case; consider upper- and lower-case letters equivalent.
-I regexp
Ignore changes that just insert or delete lines that match regexp.
--ifdef=name
Make merged if-then-else format output, conditional on the preprocessor macro name.
--ignore-all-space
Ignore white space when comparing lines.
--ignore-blank-lines
Ignore changes that just insert or delete blank lines.
--ignore-case
Ignore changes in case; consider upper- and lower-case to be the same.
--ignore-matching-lines=regexp
Ignore changes that just insert or delete lines that match regexp.
--ignore-space-change
Ignore changes in amount of white space.
--initial-tab
Output a tab rather than a space before the text of a line in normal or context format. This causes the alignment of tabs in the line to look normal.
-l
Pass the output through pr to paginate it.
-L label

--label=label
Use label instead of the file name in the context format and unified format headers.
--left-column
Print only the left column of two common lines in side by side format.
--line-format=format
Use format to output all input lines in in-then-else format.
--minimal
Change the algorithm to perhaps find a smaller set of changes. This makes diff slower (sometimes much slower).
-n
Output RCS-format diffs; like -f except that each command specifies the number of lines affected.
-N

--new-file
In directory comparison, if a file is found in only one directory, treat it as present but empty in the other directory.
--new-group-format=format
Use format to output a group of lines taken from just the second file in if-then-else format.
--new-line-format=format
Use format to output a line taken from just the second file in if-then-else format.
--old-group-format=format
Use format to output a group of lines taken from just the first file in if-then-else format.
--old-line-format=format
Use format to output a line taken from just the first file in if-then-else format.
-p
Show which C function each change is in.
-P
When comparing directories, if a file appears only in the second directory of the two, treat it as present but empty in the other.
--paginate
Pass the output through pr to paginate it.
-q
Report only whether the files differ, not the details of the differences.
-r
When comparing directories, recursively compare any subdirectories found.
--rcs
Output RCS-format diffs; like -f except that each command specifies the number of lines affected.
--recursive
When comparing directories, recursively compare any subdirectories found.
--report-identical-files

-s
Report when two files are the same.
-S file
When comparing directories, start with the file file. This is used for resuming an aborted comparison.
--from-file=file
Compare file to all operands. file can be a directory.
--to-file=file
Compare all operands to file. file can be a directory.
--sdiff-merge-assist
Print extra information to help sdiff. sdiff uses this option when it runs diff. This option is not intended for users to use directly.
--show-c-function
Show which C function each change is in.
--show-function-line=regexp
In context and unified format, for each hunk of differences, show some of the last preceding line that matches regexp.
--side-by-side
Use the side by side output format.
--speed-large-files
Use heuristics to speed handling of large files that have numerous scattered small changes.
--starting-file=file
When comparing directories, start with the file file. This is used for resuming an aborted comparison.
--suppress-common-lines
Do not print common lines in side by side format.
-t
Expand tabs to spaces in the output, to preserve the alignment of tabs in the input files.
-T
Output a tab rather than a space before the text of a line in normal or context format. This causes the alignment of tabs in the line to look normal.
--text
Treat all files as text and compare them line-by-line, even if they do not appear to be text.
-u
Use the unified output format.
--unchanged-group-format=format
Use format to output a group of common lines taken from both files in if-then-else format.
--unchanged-line-format=format
Use format to output a line common to both files in if-then-else format.
--unidirectional-new-file
When comparing directories, if a file appears only in the second directory of the two, treat it as present but empty in the other.
-U lines

--unified[=lines]
Use the unified output format, showing lines (an integer) lines of context, or three if lines is not given. For proper operation, patch typically needs at least two lines of context.
-v

--version
Output the version number of diff.
-w
Ignore white space when comparing lines.
-W columns

--width=columns
Use an output width of columns in side by side format.
-x pattern
When comparing directories, ignore files and subdirectories whose basenames match pattern.
-X file
When comparing directories, ignore files and subdirectories whose basenames match any pattern contained in file.
-y
Use the side by side output format.

SEE ALSO

cmp(1), comm(1), diff3(1), ed(1), patch(1), pr(1), sdiff(1).  

责任编辑:韩亚珊 来源: CMPP.net
相关推荐

2011-08-15 10:21:09

man中文man

2011-08-24 16:48:36

man中文man

2011-08-11 16:11:49

at中文man

2011-08-25 10:21:56

man.conf中文man

2011-08-12 14:58:05

killall中文man

2011-07-15 16:58:36

ac中文man

2011-08-15 11:10:48

more中文man

2011-08-25 17:03:51

pclose中文man

2011-08-15 14:10:37

tar中文man

2011-08-16 10:42:30

rmmod中文man

2011-08-11 17:46:02

chmod中文man

2011-08-18 13:57:38

acct中文man

2011-08-23 17:49:36

zdump中文man

2011-08-15 15:10:49

wall中文man

2011-08-23 15:06:03

quotastats中文man

2011-08-15 17:35:50

ar中文man

2011-08-25 09:07:16

suffixes中文man

2011-08-25 17:53:26

stdio中文man

2011-08-18 15:21:37

autofs中文man

2011-08-16 09:22:46

df中文man
点赞
收藏

51CTO技术栈公众号