欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > linux >内容正文

linux

linux diff(differential) 命令

发布时间:2025/4/5 linux 87 豆豆
生活随笔 收集整理的这篇文章主要介绍了 linux diff(differential) 命令 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

功能说明:比较文件的差异

语法:diff [OPTION]... FILES

实例:

diff -ur temp1 temp2

diff -ur temp1 temp2 > temp.diff

option详细:

 

--normaloutput a normal diff (This is the default).
-q, --briefreport only when files differ.
-s, --report-identical-filesreport when two files are the same.
-c, -C NUM, --context[=NUM]output NUM (default 3) lines of copied context.
-u, -U NUM, --unified[=NUM]output NUM (default 3) lines of unified context.
-e, --edoutput an ed script.
-n, --rcsoutput an RCS-format diff.
-y, --side-by-sideoutput in two columns.
-W, --width=NUMoutput at most NUM (default 130) print columns.
--left-columnoutput only the left column of common lines.
--suppress-common-linesdo not output common lines.
-p, --show-c-functionshow which C function each change is in.
-F, --show-function-line=REshow the most recent line matching RE.
--label LABELuse LABEL instead of file name (this option can be repeated).
-t, --expand-tabsexpand tabs to spaces in output.
-T, --initial-tabmake tabs line up by prepending a tab.
--tabsize=NUMtab stops every NUM (default 8) print columns.
--suppress-blank-emptysuppress space or tab before empty output lines.
-l, --paginatepass output through pr to paginate it
-r, --recursiverecursively compare any subdirectories found.
-N, --new-filetreat absent files as empty.
--unidirectional-new-filetreat absent first files as empty.
--ignore-file-name-caseignore case when comparing file names.
--no-ignore-file-name-caseconsider case when comparing file names.
-x, --exclude=PATexclude files that match PAT.
-X, --exclude-from=FILEexclude files that match any pattern in FILE.
-S, --starting-file=FILEstart with FILE when comparing directories.
--from-file=FILE1compare FILE1 to all operands; FILE1 can be a directory.
--to-file=FILE2compare all operands to FILE2; FILE2 can be a directory.
-i, --ignore-caseignore case differences in file contents.
-E, --ignore-tab-expansionignore changes due to tab expansion.
-b, --ignore-space-changeignore changes in the amount of white space.
-w, --ignore-all-spaceignore all white space.
-B, --ignore-blank-linesignore changes whose lines are all blank.
-I, --ignore-matching-lines=REignore changes whose lines all match RE.
-a, --texttreat all files as text.
--strip-trailing-crstrip trailing carriage return on input.
-D, --ifdef=NAMEoutput merged file with `#ifdef NAME' diffs.
--GTYPE-group-format=GFMTformat GTYPE input groups with GFMT.
--line-format=LFMTformat all input lines with LFMT.
--LTYPE-line-format=LFMTformat LTYPE input lines with LFMT.

These format options provide fine-grained control over the output of diff, generalizing -D/--ifdef.

LTYPE is 'old', 'new', or 'unchanged'. GTYPE is LTYPE or `changed'.

GFMT (only) may contain:

%<: lines from FILE1

%>: lines from FILE2

%=: lines common to FILE1 and FILE2.

%[-][WIDTH][.[PREC]]{doxX}LETTER: printf-style spec for LETTER

LETTERs are as follows for new group, lower case for old group:

F: first line number

L: last line number

N: number of lines = L-F+1

E: F-1

M: L+1

%(A=B?T:E) if A equals B then T else E

LFMT (only) may contain:

%L: contents of line

%l: contents of line, excluding any trailing newline

%[-][WIDTH][.[PREC]]{doxX}n: printf-style spec for input line number

Both GFMT and LFMT may contain:

%%: A literal '%'

%c'C': the single character C %c'\OOO': the character with octal code OOOC: the character C (other characters represent themselves)
-d, --minimaltry hard to find a smaller set of changes.
--horizon-lines=NUMkeep NUM lines of the common prefix and suffix.
--speed-large-filesassume large files and many scattered small changes.
--helpdisplay a help message and exit.
-v, --versionoutput version information and exit.

 

 

转载于:https://www.cnblogs.com/davidwang456/p/3518369.html

《新程序员》:云原生和全面数字化实践50位技术专家共同创作,文字、视频、音频交互阅读

总结

以上是生活随笔为你收集整理的linux diff(differential) 命令的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。