diff 中文man頁(yè)面
名字
diff - 找出兩個(gè)文件的不同點(diǎn)
總覽
diff [選項(xiàng)] 源文件 目標(biāo)文件
描述
在最簡(jiǎn)單的情況是, diff 比較兩個(gè)文件的內(nèi)容 (源文件 和 目標(biāo)文件). 文件名可以是 - 由標(biāo)準(zhǔn)輸入設(shè)備讀入的文本. 作為特別的情況是, diff - - 比較一份標(biāo)準(zhǔn)輸入的它自己的拷貝如果 源文件 是一個(gè)目錄和 目標(biāo)文件 不是(目錄), diff 會(huì)比較在 源文件(目錄) 里的文件的中和 目標(biāo)文件同名的(文件), 反過(guò)來(lái)也一樣. 非目錄文件不能是 -. 如果 源文件 和 目標(biāo)文件 都是目錄, diff 比較兩個(gè)目錄中相應(yīng)的文件,依照字母次序排序;這個(gè)比較是不會(huì)遞歸的,除非給出 -r 或者 --recursive. diff 不把一個(gè)目錄的內(nèi)容看為它是一個(gè)文件來(lái)比較。被指定的文件不能是標(biāo)準(zhǔn)的輸入, 因?yàn)闃?biāo)準(zhǔn)的輸入是無(wú)名的并且"有一樣的名字的文件"的觀點(diǎn)不適用。 diff 的選項(xiàng)由 -, 開(kāi)始所以正常地 源文件(名) 和 目標(biāo)文件(名) 不可以用 - 開(kāi)頭. 然而, -- 可以被它視為保留的即使作為文件名的開(kāi)頭( they begin with -.)
選項(xiàng)
下面是 GNU所接受的 diff 的所有選項(xiàng)的概要. 大多數(shù)的選項(xiàng)有兩個(gè)相同的名字,一個(gè)是單個(gè)的跟在 - 后面字母, 另一個(gè)是由 -- 引出的長(zhǎng)名字. 多個(gè)單字母選項(xiàng)(除非它們產(chǎn)生歧義)能夠組合為單行的命令行語(yǔ)法 -ac 是等同于 -a -c. 長(zhǎng)命名的選項(xiàng)能被縮短到他們的名字的任何唯一的前綴. 用 ([ 和 ]) 括起來(lái)顯示選項(xiàng)產(chǎn)生歧義的選項(xiàng)
- -行數(shù)(一個(gè)整數(shù))
- 顯示上下文 行數(shù) (一個(gè)整數(shù)). 這個(gè)選項(xiàng)自身沒(méi)有指定輸出格式,這是沒(méi)有效果的,除非和 -c 或者 -u 組合使用. 這是已廢置的選項(xiàng),對(duì)于正確的操作, 上下文至少要有兩行。
- -a
- 所有的文件都視為文本文件來(lái)逐行比較,甚至他們似乎不是文本文件.
- -b
- 忽略空格引起的變化.
- -B
- 忽略插入刪除空行引起的變化.
- --brief
- 僅報(bào)告文件是否相異,在乎差別的細(xì)節(jié).
- -c
- 使用上下文輸出格式.
- -C 行數(shù)(一個(gè)整數(shù))
- --context[=lines]
- 使用上下文輸出格式,顯示以指定 行數(shù) (一個(gè)整數(shù)), 或者是三行(當(dāng) 行數(shù) 沒(méi)有給出時(shí). 對(duì)于正確的操作, 上下文至少要有兩行.
- --changed-group-format=format
- 使用 format 輸出一組包含兩個(gè)文件的不同處的行,其格式是 if-then-else .
- -d
- 改變算法也許發(fā)現(xiàn)變化的一個(gè)更小的集合.這會(huì)使 diff 變慢 (有時(shí)更慢).
- -D name
- 合并 if-then-else 格式輸出, 預(yù)處理宏(由name參數(shù)提供)條件.
- -e
- --ed
- 輸出為一個(gè)有效的 ed 腳本.
- --exclude=pattern
- 比較目錄的時(shí)候,忽略和目錄中與 pattern(樣式) 相配的.
- --exclude-from=file
- 比較目錄的時(shí)候,忽略和目錄中與任何包含在 file(文件) 的樣式相配的文件和目錄.
- --expand-tabs
- 在輸出時(shí)擴(kuò)展tab為空格,保護(hù)輸入文件的tab對(duì)齊方式
- -f
- 產(chǎn)生一個(gè)很象 ed 腳本的輸出,但是但是在他們?cè)谖募霈F(xiàn)的順序有改變
- -F regexp
- 在上下文和統(tǒng)一格式中,對(duì)于每一大塊的不同,顯示出匹配 regexp. 的一些前面的行.
- --forward-ed
- 產(chǎn)生象 ed 腳本的輸出,但是它們?cè)谖募霈F(xiàn)的順序有改變。
- -h
- 這選項(xiàng)現(xiàn)在已沒(méi)作用,它呈現(xiàn)Unix的兼容性.
- -H
- 使用啟發(fā)規(guī)則加速操作那些有許多離散的小差異的大文件.
- --horizon-lines=lines
- 比較給定行數(shù)的有共同前綴的最后行,和有共同或綴的最前行.
- -i
- 忽略大小寫.
- -I regexp
- 忽略由插入,刪除行(由regexp 參數(shù)提供參考)帶來(lái)的改變.
- --ifdef=name
- 合并 if-then-else 格式輸出, 預(yù)處理宏(由name參數(shù)提供)條件.
- --ignore-all-space
- 在比較行的時(shí)候忽略空白.
- --ignore-blank-lines
- 忽略插入和刪除空行
- --ignore-case
- 忽略大小寫.
- --ignore-matching-lines=regexp
- 忽略插入刪除行(由regexp 參數(shù)提供參考).
- --ignore-space-change
- 忽略空白的數(shù)量.
- --initial-tab
- 在文本行(無(wú)論是常規(guī)的或者格式化的前后文關(guān)系)前輸出tab代替空格. 引起的原因是tab對(duì)齊方式看上去象是常規(guī)的一樣.
- -l
- 產(chǎn)生通過(guò) pr 編碼的輸出.
- -L label
- --label=label
- 使用 label 給出的字符在文件頭代替文件名輸出.
- --left-column
- 以并列方式印出兩公共行的左邊
- --line-format=format
- 使用 format 輸出所有的行,在 if-then-else 格式中.
- --minimal
- 改變算法也許發(fā)現(xiàn)變化的一個(gè)更小的集合.這會(huì)使 diff 變慢 (有時(shí)更慢).
- -n
- 輸出 RC-格式 diffs; 除了每條指令指定的行數(shù)受影響外 象 -f 一樣。
- -N
- --new-file
- 在目錄比較中,如果那個(gè)文件只在其中的一個(gè)目錄中找到,那么它被視為在另一個(gè)目錄中是一個(gè)空文件.
- --new-group-format=format
- 使用 format 以if-then-else 格式輸出只在第二個(gè)文件中取出的一個(gè)行組
- --new-line-format=format
- 使用 format 以if-then-else 格式輸出只在第二個(gè)文件中取出的一行
- --old-group-format=format
- 使用 format 以if-then-else 格式輸出只在第一個(gè)文件中取出的一個(gè)行組
- --old-line-format=format
- 使用 format 使用 format 以if-then-else 格式輸出只在第一個(gè)文件中取出的一行
- -p
- 顯示帶有c函數(shù)的改變.
- -P
- 在目錄比較中,如果那個(gè)文件只在其中的一個(gè)目錄中找到,那么它被視為在另一個(gè)目錄中是一個(gè)空文件.
- --paginate
- 產(chǎn)生通過(guò) pr 編碼的輸出.
- -q
- 僅報(bào)告文件是否相異,不報(bào)告詳細(xì)的差異.
- -r
- 當(dāng)比較目錄時(shí),遞歸比較任何找到的子目錄.
- --rcs
- 輸出 RC-格式 diffs; 除了每條指令指定的行數(shù)受影響外 象 -f 一樣。
- --recursive
- 當(dāng)比較目錄時(shí),遞歸比較任何找到的子目錄.
- --report-identical-files
- -s
- 報(bào)告兩個(gè)文件相同.
- -S file
- 當(dāng)比較目錄時(shí),由 file 開(kāi)始. 這用于繼續(xù)中斷了的比較.
- --sdiff-merge-assist
- 打印附加的信息去幫助 sdiff. sdiff 在運(yùn)行 diff 時(shí)使用這些選項(xiàng). 這些選項(xiàng)不是特意為使用者直接使用而準(zhǔn)備的。
- --show-c-function
- 顯示帶有c函數(shù)的改變.
- --show-function-line=regexp
- 在上下文和統(tǒng)一的格式,對(duì)于每一大塊的差別,顯示出匹配 regexp. 的一些前面的行
- --side-by-side
- 使用并列的輸出格式.
- --speed-large-files
- 使用啟發(fā)規(guī)則加速操作那些有許多離散的小差異的大文件.
- --starting-file=file
- 當(dāng)比較目錄時(shí),由 file 開(kāi)始. 這用于繼續(xù)中斷了的比較.
- --suppress-common-lines
- 在并列格式中不印出公共行。
- -t
- 在輸出時(shí)擴(kuò)展tab為空格,保護(hù)輸入文件的tab對(duì)齊方式
- -T
- 在文本行(無(wú)論是常規(guī)的或者格式化的前后文關(guān)系)前輸出tab代替空格.引起的原因是tab對(duì)齊方式看上去象是常規(guī)的一樣.
- --text
- 所有的文件都視為文本文件來(lái)逐行比較,甚至他們似乎不是文本文件.
- -u
- 使用統(tǒng)一的輸出格式.
- --unchanged-group-format=format
- 使用 format 輸出兩個(gè)文件的公共行組,其格式是if-then-else.
- --unchanged-line-format=format
- 使用 format 輸出兩個(gè)文件的公共行,其格式是if-then-else.
- --unidirectional-new-file
- 在目錄比較中,如果那個(gè)文件只在其中的一個(gè)目錄中找到,那么它被視為在另一個(gè)目錄中是一個(gè)空文件.
- -U lines
- --unified[=lines]
- 使用前后關(guān)系格式輸出,顯示以指定 行數(shù) (一個(gè)整數(shù)), 或者是三行(當(dāng) 行數(shù) 沒(méi)有給出時(shí). 對(duì)于正確的操作, 上下文至少要有兩行.
- -v
- --version
- 輸出 diff 版本號(hào).
- -w
- 在比較行時(shí)忽略空格
- -W columns
- --width=columns
- 在并列格式輸出時(shí),使用指定的列寬.
- -x pattern
- 比較目錄的時(shí)候,忽略和目錄中與 pattern(樣式) 相配的.
- -X file
- 比較目錄的時(shí)候,忽略和目錄中與任何包含在 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).