--normal ——正常
output a normal diff (the default)
输出正常差异(默认)
-q, --brief ——简短
report only when files differ
仅当文件不同时才报告
-s, --report-identical-files -报告相同的文件
report when two files are the same
当两个文件相同时报告
-c, -C NUM, --context[=NUM] - C数字,-上下文=数字
output NUM (default 3) lines of copied context
输出数字(默认3)复制上下文的行
-u, -U NUM, --unified[=NUM] -u数字,统一=数字
output NUM (default 3) lines of unified context
输出数字(默认3)统一上下文的行
-e, --ed
output an ed script 输出脚本
-n, --rcs
output an RCS format diff 输出RCS格式差异
-y, --side-by-side -并排
output in two columns 两列输出
-W, --width=NUM -宽度=数字
output at most NUM (default 130) print columns
输出最多数字(默认130)打印列
--left-column 左栏
output only the left column of common lines
只输出普通行的左列
--suppress-common-lines -抑制公共行
do not output common lines 不输出公用行
-p, --show-c-function 显示C函数
show which C function each change is in
显示每个更改中的C函数
-F, --show-function-line=RE 显示函数线
show the most recent line matching RE
显示最近的线路匹配
--label LABEL ——标签
use LABEL instead of file name (can be repeated)
使用标签代替文件名(可重复)
-t, --expand-tabs -扩展标签
expand tabs to spaces in output
将制表符扩展到输出空间
-T, --initial-tab -初始制表符
make tabs line up by prepending a tab
使标签排队前面加上标签
--tabsize=NUM
tab stops every NUM (default 8) print columns
制表符停止每个数字(默认值8)打印列
--suppress-blank-empty -压制空白空
suppress space or tab before empty output lines
在空输出行之前抑制空间或制表符
-l, --paginate —分页
pass output through 'pr' to paginate it
-r, --recursive ——递归
recursively compare any subdirectories found
任何子目录递归比较发现
--no-dereference 没有引用
don't follow symbolic links 不要遵循符号链接
-N, --new-file 新文件
treat absent files as empty 将缺席文件视为空
--unidirectional-new-file 单向新文件
treat absent first files as empty 将缺席的第一文件视为空
--ignore-file-name-case ——忽略文件名
ignore case when comparing file names 在比较文件名时忽略实例
--no-ignore-file-name-case -没有忽略的文件名的情况下
consider case when comparing file names 比较文件名时考虑案例
-x, --exclude=PAT -排除= PAT
exclude files that match PAT
排除匹配PAT的文件
-X, --exclude-from=FILE 从文件中排除
exclude files that match any pattern in FILE
排除与文件中任何模式匹配的文件
-S, --starting-file=FILE 启动文件=文件
start with FILE when comparing directories
在比较目录时启动文件
--from-file=FILE1 从文件file1
compare FILE1 to all operands; FILE1 can be a directory
比较1所有操作数可以是一个目录的文件;
--to-file=FILE2 --文件file2
compare all operands to FILE2; FILE2 can be a directory
比较所有的操作数可以是一个目录的源文件源文件;
-i, --ignore-case --忽略案例
ignore case differences in file contents
忽略文件内容中的实例差异
-E, --ignore-tab-expansion -忽略制表扩展
ignore changes due to tab expansion
忽略选项卡扩展所带来的更改
-Z, --ignore-trailing-space -忽略尾随空间
ignore white space at line end
忽略行端空白
-b, --ignore-space-change -忽略空间变化
ignore changes in the amount of white space
将一串空格或TAB 转换成一个空格或TAB
-w, --ignore-all-space -忽略所有空间
ignore all white space
忽略所有空白
-B, --ignore-blank-lines -忽略空白行
ignore changes where lines are all blank
忽略线条都是空白的更改
-I, --ignore-matching-lines=RE 忽略匹配线
ignore changes where all lines match RE
忽略所有行重新匹配的更改
-a, --text 文本
treat all files as text
将所有文件视为文本
--strip-trailing-cr 带状拖尾
strip trailing carriage return on input
带尾随回车输入
-D, --ifdef=NAME
output merged file with '#ifdef NAME' diffs
输出文件合并与# ifdef名字的差别
--GTYPE-group-format=GFMT ——型组格式= gfmt
format GTYPE input groups with GFMT
格式输入组gfmt型
--line-format=LFMT ——行格式= lfmt
format all input lines with LFMT
格式的所有输入线lfmt
--LTYPE-line-format=LFMT ——线型线格式= lfmt
format LTYPE input lines with LFMT
总有lfmt格式输入线
[root@localhost ~]# diff -c /aaa/file1 /aaa/file2 输出数字并复制上下文的行
*** /aaa/file1 2017-04-30 21:21:43.262369811 -0400
--- /aaa/file2 2017-04-30 21:21:59.381369811 -0400
***************
*** 1,5 ****
123
! sadd
! vx
! wer
! xvc
--- 1,5 ----
+ jdsaj
+ jdsa
123
! ckl
! dsak
[root@localhost ~]# diff -u /aaa/file1 /aaa/file2 输出数字统一上下文的行
--- /aaa/file1 2017-04-30 21:21:43.262369811 -0400
+++ /aaa/file2 2017-04-30 21:21:59.381369811 -0400
@@ -1,5 +1,5 @@
+jdsaj
+jdsa
123
-sadd
-vx
-wer
-xvc
+ckl
+dsak
[root@localhost ~]# diff -r /aaa/ /mnt/ 对两个目录进行递归式比较
Only in /aaa/: file1
Only in /aaa/: file2
Only in /mnt/: test1
[root@localhost ~]# diff -r /aaa /mnt 对两个目录进行递归式比较,两个目录中有文件名相同,但内容不同的文件时会出现下边这种
Only in /aaa: bbb
Only in /mnt: ccc
diff -r /aaa/file1 /mnt/file1
5a6
>
Only in /aaa: file2
[root@localhost ~]# diff -r /aaa /mnt 对两个目录进行递归式比较,两个目录中有文件名相同,但内容相同的文件时会出现下边这种
Only in /aaa: bbb
Only in /mnt: ccc
Only in /aaa: file2
[root@localhost ~]# diff -r -s /aaa /mnt 对两个目录进行递归式比较,-s表示当文件名及内容相同时报告
Only in /aaa: bbb
Only in /mnt: ccc
Files /aaa/file1 and /mnt/file1 are identical
Only in /aaa: file2
[root@localhost ~]# diff -y /mnt/file1 /aaa/file1 并排输出两个文件的内容
123 123
sadd sadd
vx vx
wer wer
xvc xvc
在练习patch命令之前,首先需要有patch这个服务,先自行安装patch
patch 采用补丁文件 patchfile ( 包含由 diff 生成的差异列表 ) 并将这
些差异应用于生成补丁版的一个或多个原始文件。通常 , 补丁版替换原
始文件 , 但当指定 -b 选项时 , 可以制作备份。将用 .orig 文件名后缀
重命名原始文件
• patch 可用于将简单的补丁文件应用于使用以下语法的单个文件
– [root@host etc]# patch issue patchfile
Patching file issue
•
以下命令显示如何使用通过 diff -Naur 创建的补丁文件。用户更改为
与从中创建补丁文件的原始目录相似的可比较目录后 , 将执行 patch
– [user@host orig-dir]$ patch -b < /tmp/patchfile
Patching file hosts
Patching file network
-b or --backup
Make backup files. That is, when patching a file, rename or copy
the original instead of removing it. When backing up a file that
does not exist, an empty, unreadable backup file is created as a
placeholder to represent the nonexistent file. See the -V or --ver‐
sion-control option for details about how backup file names are
determined.
备份制作备份文件。也就是说,当修补文件,重命名或复制原来的,而不是删除它。备份文件时不存在, 空,无法读取备份文件创建一个占位符表示不存在的文件。看到V或v关于如何备份文件名的详细控制选项确定。
--backup-if-mismatch
Back up a file if the patch does not match the file exactly and if
backups are not otherwise requested. This is the default unless
patch is conforming to POSIX.
--no-backup-if-mismatch
Do not back up a file if the patch does not match the file exactly
and if backups are not otherwise requested. This is the default if
patch is conforming to POSIX.
-B pref or --prefix=pref
Use the simple method to determine backup file names (see the -V
method or --version-control method option), and append pref to a
file name when generating its backup file name. For example, with
-B /junk/ the simple backup file name for src/patch/util.c is
/junk/src/patch/util.c.
--binary -二进制
Write all files in binary mode, except for standard output and
/dev/tty. When reading, disable the heuristic for transforming CRLF
line endings into LF line endings. This option is needed on POSIX
systems when applying patches generated on non-POSIX systems to non-
POSIX files. (On POSIX systems, file reads and writes never trans‐
form line endings. On Windows, reads and writes do transform line
endings by default, and patches should be generated by diff --binary
when line endings are significant.)
将所有文件写入二进制模式,除了标准输出和/dev/tty。阅读时,禁用启发式转变时线结局为LF线结局。此选项需要对POSIX当应用产生非POSIX系统非补丁系统—POSIX文件。(POSIX系统,文件读取和写入不跨‐
表格线结尾。在windows上,读写做变换行默认情况下结束,补丁应该由二进制当线的结局是显著的。)
-c or --context 上下文
Interpret the patch file as a ordinary context diff.
解释的补丁文件作为一个普通的上下文差异
-d dir or --directory=dir
Change to the directory dir immediately, before doing anything else.
立即更改目录目录,然后再做其他事情
-D define or --ifdef=define 定义ifdef =
Use the #ifdef ... #endif construct to mark changes, with define as
the differentiating symbol.
使用# ifdef…# endif构造标记的变化,定义为鉴别符号。
[root@localhost ~]# diff -u /aaa/file2 /mnt/file1 >patchfile
[root@localhost ~]# cat patchfile
--- /aaa/file2 2017-04-30 21:21:59.381369811 -0400
+++ /mnt/file1 2017-04-30 22:36:33.544369811 -0400
@@ -1,5 +1,5 @@
-jdsaj
-jdsa
123
-ckl
-dsak
+sadd
+vx
+wer
+xvc
[root@localhost ~]# patch /aaa/file1 patchfile 给/aaa/file1打补丁
patching file /aaa/file1
Reversed (or previously applied) patch detected! Assume -R? [n] y
[root@localhost ~]# cat /aaa/file1
jdsaj
jdsa
123
ckl
dsak
[root@localhost ~]# patch -b /aaa/file1 patchfile ##给/aaa/file1打补丁,并对/aaa/file1备份,生成file1.org文件
patching file /aaa/file1
Reversed (or previously applied) patch detected! Assume -R? [n] y
[root@localhost ~]# cd /aaa/
[root@localhost aaa]# ls
bbb file1 file1.orig file2