FreeBSD 中文 man 手册
FreeBSD 中文社区
  • man
  • man1
    • Mail.1
    • addr2line.1
    • alias.1
    • alloc.1
    • apply.1
    • apropos.1
    • ar.1
    • at.1
    • atq.1
    • atrm.1
    • awk.1
    • basename.1
    • batch.1
    • bc.1
    • bg.1
    • bind.1
    • bindkey.1
    • break.1
    • breaksw.1
    • bsdcat.1
    • bsdtar.1
    • btsockstat.1
    • builtin.1
    • builtins.1
    • c++.1
    • case.1
    • cat.1
    • cc.1
    • chdir.1
    • chfn.1
    • chgrp.1
    • chkey.1
    • chmod.1
    • cksum.1
    • clang++.1
    • clang-cpp.1
    • cmp.1
    • colrm.1
    • column.1
    • comm.1
    • command.1
    • complete.1
    • continue.1
    • cp.1
    • cpp.1
    • crypt.1
    • csh.1
    • ctfdump.1
    • cut.1
    • date.1
    • dd.1
    • default.1
    • df.1
    • dialog.1
    • diff.1
    • diff3.1
    • dirname.1
    • dirs.1
    • do.1
    • done.1
    • dtrace.1
    • du.1
    • echo.1
    • echotc.1
    • edit.1
    • ee.1
    • egrep.1
    • elfdump.1
    • elif.1
    • else.1
    • end.1
    • endif.1
    • endsw.1
    • enigma.1
    • env.1
    • esac.1
    • eval.1
    • exec.1
    • exit.1
    • export.1
    • fc.1
    • fg.1
    • fgrep.1
    • fi.1
    • filetest.1
    • find.1
    • for.1
    • foreach.1
    • fsync.1
    • ftp.1
    • fuser.1
    • gate-ftp.1
    • getopts.1
    • glob.1
    • goto.1
    • grep.1
    • groups.1
    • gunzip.1
    • gzcat.1
    • gzip.1
    • hash.1
    • hashstat.1
    • head.1
    • history.1
    • host.1
    • hostname.1
    • hup.1
    • ibv_asyncwatch.1
    • ibv_devices.1
    • ibv_devinfo.1
    • ibv_ud_pingpong.1
    • id.1
    • ident.1
    • if.1
    • intro.1
    • introduction.1
    • jobid.1
    • jobs.1
    • kdump.1
    • kenv.1
    • keylogin.1
    • keylogout.1
    • kill.1
    • killall.1
    • ktrace.1
    • last.1
    • lastcomm.1
    • ld.1
    • ld.lld.1
    • ldd.1
    • ldd32.1
    • less.1
    • lessecho.1
    • limit.1
    • limits.1
    • link.1
    • llvm-addr2line.1
    • llvm-ranlib.1
    • ln.1
    • locate.1
    • lockstat.1
    • log.1
    • logger.1
    • login.1
    • logname.1
    • logout.1
    • look.1
    • lorder.1
    • ls-F.1
    • ls.1
    • lsvfs.1
    • lzcat.1
    • lzma.1
    • lzmadec.1
    • lzmainfo.1
    • mailx.1
    • make.1
    • man.1
    • mandoc.1
    • manpath.1
    • md5.1
    • mdocml.1
    • mkdir.1
    • mkfilters.1
    • more.1
    • mv.1
    • nawk.1
    • nc.1
    • netstat.1
    • newaliases.1
    • nice.1
    • notify.1
    • onintr.1
    • pagesize.1
    • passwd.1
    • paste.1
    • pax.1
    • perror.1
    • pftp.1
    • popd.1
    • printenv.1
    • ps.1
    • pushd.1
    • pwd.1
    • qemu.1
    • ranlib.1
    • read.1
    • readelf.1
    • readlink.1
    • readonly.1
    • realpath.1
    • ree.1
    • rehash.1
    • repeat.1
    • rev.1
    • revoke.1
    • rgrep.1
    • rm.1
    • rmd16.1
    • rmdir.1
    • rping.1
    • ruptime.1
    • rwho.1
    • sched.1
    • scp.1
    • sdiff.1
    • sed.1
    • seq.1
    • set.1
    • setenv.1
    • settc.1
    • setty.1
    • setvar.1
    • sftp.1
    • sh.1
    • sha1.1
    • sha224.1
    • sha256.1
    • sha384.1
    • sha512.1
    • sha512t256.1
    • shift.1
    • skein1024.1
    • skein256.1
    • skein512.1
    • slogin.1
    • sockstat.1
    • sort.1
    • source.1
    • split.1
    • ssh-copy-id.1
    • ssh-keygen.1
    • ssh.1
    • stat.1
    • stop.1
    • su.1
    • suspend.1
    • svnlite.1
    • switch.1
    • systat.1
    • tail.1
    • tar.1
    • tcpdump.1
    • tcsh.1
    • telltc.1
    • telnet.1
    • then.1
    • time.1
    • timeout.1
    • times.1
    • top.1
    • touch.1
    • trap.1
    • truncate.1
    • truss.1
    • type.1
    • ulimit.1
    • umask.1
    • unalias.1
    • uname.1
    • uncomplete.1
    • unhash.1
    • uniq.1
    • unlimit.1
    • unlink.1
    • unlzma.1
    • unset.1
    • unsetenv.1
    • until.1
    • unxz.1
    • uptime.1
    • users.1
    • uuidgen.1
    • view.1
    • w.1
    • wait.1
    • wall.1
    • wc.1
    • whatis.1
    • where.1
    • whereis.1
    • which.1
    • while.1
    • who.1
    • whoami.1
    • xargs.1
    • xz.1
    • xzcat.1
    • xzdec.1
    • xzdiff.1
    • yes.1
    • yppasswd.1
    • zcat.1
    • zcmp.1
    • zdiff.1
    • zforce.1
    • zless.1
    • zmore.1
    • znew.1
  • man4
    • ow.4
    • ow_temp.4
    • owc.4
  • man5
    • device.hints.5
  • man7
    • hire
  • man8
    • adduser.8
    • authpf-noip.8
    • authpf.8
    • autounmountd.8
    • beastie.4th.8
    • bhyve.8
    • bhyvectl.8
    • bhyveload.8
    • blacklistctl.8
    • boot.8
    • boot0cfg.8
    • boot_i386.8
    • bsdconfig.8
    • camcontrol.8
    • check-password.4th.8
    • chown.8
    • chroot.8
    • config.8
    • crash.8
    • crashinfo.8
    • devctl.8
    • devinfo.8
    • devmatch.8
    • diskinfo.8
    • dmesg.8
    • fastboot.8
    • fasthalt.8
    • freebsd-update.8
    • fstyp.8
    • ftp-proxy.8
    • ftpd.8
    • gpart.8
    • gpioctl.8
    • gptboot.8
    • gptzfsboot.8
    • growfs.8
    • halt.8
    • i2c.8
    • ifconfig.8
    • inetd.8
    • init.8
    • intro.8
    • iostat.8
    • ipfw.8
    • jail.8
    • jexec.8
    • jls.8
    • kldconfig.8
    • kldload.8
    • kldstat.8
    • kldunload.8
    • kldxref.8
    • lastlogin.8
    • loader.4th.8
    • loader.8
    • loader.efi.8
    • mail.local.8
    • mailstats.8
    • menu.4th.8
    • mount.8
    • mount_cd9660.8
    • mount_msdosfs.8
    • moused.8
    • mtree.8
    • natd.8
    • nmtree.8
    • ntptime.8
    • password.lua.8
    • periodic.8
    • ping.8
    • pkg.8
    • pmccontrol.8
    • pmcstat.8
    • powerd.8
    • poweroff.8
    • pw.8
    • pwm.8
    • quot.8
    • rarpd.8
    • rc.8
    • rc.d.8
    • rc.firewall.8
    • rc.local.8
    • rc.network.8
    • rc.pccard.8
    • rc.resume.8
    • rc.serial.8
    • rc.shutdown.8
    • rc.subr.8
    • rcorder.8
    • reboot.8
    • renice.8
    • rescue.8
    • rmuser.8
    • route.8
    • route6d.8
    • routed.8
    • rpc.rusersd.8
    • service.8
    • shutdown.8
    • spi.8
    • ssh-keysign.8
    • sysctl.8
    • sysrc.8
    • tcpdrop.8
    • tftpd.8
    • tzsetup.8
    • umount.8
    • vmstat.8
    • watchdog.8
    • watchdogd.8
    • zfs.8
由 GitBook 提供支持

FreeBSD 中文社区

在本页
  • 名称
  • 概要
  • 描述
  • 输出风格
  • 文件
  • 退出状态
  • 实例
  • 参见
  • 标准
  • 历史

这有帮助吗?

在GitHub上编辑
导出为 PDF
  1. man1

diff.1

上一页dialog.1下一页diff3.1

最后更新于1年前

这有帮助吗?

DIFF(1)

DIFF(1)

FreeBSD General Commands Manual

DIFF(1)

diff —

差异文件和目录比较器

diff [-aBbdipTtw] [-c | -e | -f | -n | -q | -u | -y] [--brief] [--changed-group-format GFMT] [--ed] [--expand-tabs] [--forward-ed] [--ignore-all-space] [--ignore-case] [--ignore-space-change] [--initial-tab] [--minimal] [--no-ignore-file-name-case] [--normal] [--rcs] [--show-c-function] [--starting-file] [--speed-large-files] [--strip-trailing-cr] [--tabsize number] [--text] [--unified] [-I pattern | --ignore-matching-lines pattern] [-L label | --label label] file1 file2 diff [-aBbdilpTtw] [-I pattern | --ignore-matching-lines pattern] [-L label | --label label] [--brief] [--changed-group-format GFMT] [--ed] [--expand-tabs] [--forward-ed] [--ignore-all-space] [--ignore-case] [--ignore-space-change] [--initial-tab] [--minimal] [--no-ignore-file-name-case] [--normal] [--paginate] [--rcs] [--show-c-function] [--speed-large-files] [--starting-file] [--strip-trailing-cr] [--tabsize number] [--text] -C number | -context number file1 file2 diff [-aBbdiltw] [-I pattern | --ignore-matching-lines pattern] [--brief] [--changed-group-format GFMT] [--ed] [--expand-tabs] [--forward-ed] [--ignore-all-space] [--ignore-case] [--ignore-space-change] [--initial-tab] [--minimal] [--no-ignore-file-name-case] [--normal] [--paginate] [--rcs] [--show-c-function] [--speed-large-files] [--starting-file] [--strip-trailing-cr] [--tabsize number] [--text] -D string | --ifdef string file1 file2 diff [-aBbdilpTtw] [-I pattern | --ignore-matching-lines pattern] [-L label | --label label] [--brief] [--changed-group-format GFMT] [--ed] [--expand-tabs] [--forward-ed] [--ignore-all-space] [--ignore-case] [--ignore-space-change] [--initial-tab] [--minimal] [--no-ignore-file-name-case] [--normal] [--paginate] [--rcs] [--show-c-function] [--speed-large-files] [--starting-file] [--strip-trailing-cr] [--tabsize number] [--text] -U number | --unified number file1 file2 diff [-aBbdilNPprsTtw] [-c | -e | -f | -n | -q | -u] [--brief] [--changed-group-format GFMT] [--context] [--ed] [--expand-tabs] [--forward-ed] [--ignore-all-space] [--ignore-case] [--ignore-space-change] [--initial-tab] [--minimal] [--new-file] [--no-ignore-file-name-case] [--normal] [--paginate] [--rcs] [--recursive] [--report-identical-files] [--show-c-function] [--speed-large-files] [--strip-trailing-cr] [--tabsize number] [--text] [--unidirectional-new-file] [--unified] [-I pattern | --ignore-matching-lines pattern] [-L label | --label label] [-S name | --starting-file name] [-X file | --exclude-from file] [-x pattern | --exclude pattern] dir1 dir2 diff [-aBbditwW] [--expand-tabs] [--ignore-all-blanks] [--ignore-blank-lines] [--ignore-case] [--minimal] [--no-ignore-file-name-case] [--strip-trailing-cr] [--suppress-common-lines] [--tabsize number] [--text] [--width] -y | --side-by-side file1 file2

diff 实用程序比较 file1 和 file2 的内容,并将将一个文件转换为另一个文件所需的更改列表写入标准输出。 如果文件相同,则不会产生输出。

输出选项(互斥):

number --context number

与 -c 类似,但会产生带有上下文 number 行的差异。

产生具有 3 行上下文的差异。 使用 -c 会稍微修改输出格式:输出以识别所涉及的文件及其创建日期开始,然后每个更改由带有 15 个 * 的行分隔。 从 file1 中删除的行标有 ‘- ’; 添加到 file2 的那些标记为 ‘+ ’ 。 从一个文件更改到另一个文件的行在两个文件中都标有 ‘! ’ 。 彼此相距 3 行以内的更改在输出时被组合在一起。

在标准输出上创建 file1 和 file2 的合并版本,其中包含 C 预处理器控件,以便在不定义 string 的情况下编译结果等同于编译 file1, 而定义 string 将产生 file2 。

以适合作为编辑器实用程序 ed(1) 输入的形式生成输出,然后可以使用该格式将 file1 转换为 file2。

使用 -e 比较目录时,会在输出中添加额外的命令,因此结果是一个 sh(1) 脚本,用于将两个目录共有的文本文件从它们在 dir1 中的状态转换为它们在 dir2 中的状态。

与 -e 标志的输出相同,但顺序相反。 它不能被 ed(1) 消化。

生成一个类似于 -e 的脚本,但顺序相反,并且在每个插入或删除命令上都有更改的行数。 这是 rcsdiff 使用的形式。

当文件不同时,只需打印一行。 不输出更改列表。

与 -u 类似,但会产生带有上下文 number 行的差异。

生成具有 3 行上下文的 unified 差异。 统一差异类似于 -c 选项产生的上下文差异。 然而,与 -c 不同的是,所有要更改(添加和/或删除)的行都存在于单个部分中。

在两列中输出,它们之间有一个标记。 标记可以是以下之一:

space

对应的行是相同的。

'|'

对应的线路不同。

'<'

文件不同,只有第一个文件包含该行。

'>'

文件不同,只有第二个文件包含该行。

比较选项:

将所有文件视为 ASCII 文本。 如果文件包含二进制字符,通常 diff 将简单地打印 “Binary files ... differ” 。 使用此选项会强制 diff 产生差异。

导致只包含空行的块被忽略

导致尾随空格(空格和制表符)被忽略,其他空格字符串比较相等。

非常努力地产生尽可能小的差异。 在处理具有许多更改的大型文件时,这可能会消耗大量的处理能力和内存。

忽略行与扩展正则表达式 pattern 匹配的更改、插入和删除。 可以指定多个 -I 模式。 更改中的所有行都必须匹配某些模式才能忽略更改。 有关正则表达式模式的更多信息,请参阅 re_format(7) 。

忽略字母的大小写。 例如, “A” 将等于 “a” 。

通过 pr(1) 传递输出以对其进行分页。

打印 label 而不是上下文或统一差异标头中的第一个(和第二个,如果此选项被指定两次)文件名和时间。

使用统一和上下文差异,每次更改时显示上下文前最后一行的前 40 个字符,以字母、下划线或美元符号开头。 对于遵循标准布局约定的 C 源代码,这将显示更改适用的函数的原型。

对于正常、上下文或统一的输出格式,在该行的其余部分之前打印一个制表符而不是一个空格。 这使得行中的制表符对齐一致。

将展开输出行中的选项卡。 正常或 -c 输出将字符添加到每行的前面,这可能会破坏原始源代码行的缩进并使输出列表难以解释。 此选项将保留原始源的缩进。

类似于 -b --ignore-space-change 但会导致空格(空格和制表符)被完全忽略。 例如, “if ( a == b )” 将比较等于 “if(a==b)” 。

使用并排格式时最多输出 number 列。 默认值为 130。

在提供的格式输入组

格式是带有特殊关键字的字符串:

%<

FILE1 中的行

%<

来自 FILE2 的行

比较文件名时忽略大小写

不要忽略大小写比较文件名(默认)

默认差异输出

与 GNU diff 兼容的存根选项

删除输入文件上的回车

使用并排格式时不输出公共行

代表制表符的空格数(默认 8)

目录比较选项:

如果一个文件只在一个目录中找到,就好像它也在另一个目录中找到但大小为零一样。

如果一个文件只在 dir2 中找到,就好像它也在 dir1 中找到但大小为零一样。

导致将 diff 递归应用到遇到的公共子目录。

在中间重新启动一个目录 diff ,以文件 name 开头。

导致 diff 报告相同的文件,否则未提及。

从比较中排除其基本名称与 file 中的行匹配的文件和子目录。 可以指定多个 -X 选项。

从比较中排除基本名称与 pattern 匹配的文件和子目录。 通过 fnmatch(3) 使用 shell 样式的通配符匹配模式。 可以指定多个 -x 选项。

如果两个参数都是目录,则 diff 按名称对目录的内容进行排序,然后对不同的文本文件运行常规文件 diff 算法,生成更改列表。 不同的二进制文件、公共子目录和只出现在一个目录中的文件都被这样描述。 在目录模式下,仅比较常规文件和目录。 如果遇到非常规文件,例如设备特殊文件或 FIFO,则会打印诊断消息。

如果 file1 和 file2 中只有一个是目录,则 diff 应用于非目录文件以及目录文件中包含的文件名与非目录文件的最后一个组件相同的文件。

如果 file1 或 file2 是 ‘-’, 则使用标准输入代替它。

默认(不带 -e -、 -c 或 -n --rcs 选项)输出包含这些形式的行,其中 XX, YY, ZZ, QQ 分别是文件顺序的行号。

在 file1 的第 XX 行(末尾)处,附加 file2 的第 YY 行的内容以使它们相等。

同上,但将 file2 的 YY 到 ZZ 的行范围附加到文件 1 的 XX 行。

在第 XX 行删除该行。 值 YY 告诉哪一行更改将使 file1 与 file2 保持一致。

删除 file1 中的 XX 到 YY 行范围。

将 file1 中的 XX 行更改为 file2 中的 YY 行。

用 ZZ 行替换指定行的范围。

将 file1 中的 XX,YY 范围替换为 file2 中的 ZZ,QQ 范围。

这些行类似于将 file1 转换为 file2 的 ed(1) 子命令。 动作字母前的行号与 file1 相关;后面的属于 file2 。 因此,通过将 a 替换为 d 并以相反的顺序读取该行,还可以确定如何将 file2 转换为 file1 。 与 ed(1) 中一样,相同的对(其中 num1 = num2)被缩写为单个数字。

/tmp/diff.XXXXXXXX

比较设备或标准输入时使用的临时文件。 请注意,临时文件在创建后立即取消链接,因此它不会显示在目录列表中。

diff 实用程序以下列值之一退出:

0

没有发现差异。

1

发现了差异。

>1

发生错误。

比较 old_dir 和 new_dir 递归生成统一差异并将仅在这些目录之一中找到的文件视为新文件:

$ diff -ruN /path/to/old_dir /path/to/new_dir

同上,但不包括匹配表达式 “*.h” 和 “*.c” 的文件:

$ diff -ruN -x '*.h' -x '*.c' /path/to/old_dir /path/to/new_dir

显示单行指示文件是否不同:

$ diff -q /boot/loader.conf /boot/defaults/loader.conf 文件 /boot/loader.conf 和 /boot/defaults/loader.conf 不同

假设一个名为 example.txt 的文件具有以下内容:

FreeBSD 是一个操作系统 Linux是一个内核 OpenBSD 是一个操作系统

将 stdin 与 example.txt 进行比较,从比较中排除包含 “Linux” 或 “Open” 的行:

$ echo "FreeBSD is an operating system" | diff -q -I 'Linux|Open' example.txt -

cmp(1), comm(1), diff3(1), ed(1), patch(1), pr(1), sdiff(1) James W. Hunt and M. Douglas McIlroy, An Algorithm for Differential File Comparison, Computing Science Technical Report, Bell Laboratories 41, June 1976.

diff 实用程序符合 IEEE Std 1003.1-2008 (“POSIX.1”) 规范。

标志 [-aDdIiLlNnPpqSsTtwXxy] 是对该规范的扩展。

diff 命令出现在 Version 6 AT&T UNIX 中。

June 19, 2020

FreeBSD 13.1-RELEASE

string --ifdef string

--ed

--forward-ed

--brief

number --unified number

--side-by-side

--text

--ignore-blank-lines

--ignore-space-change

--minimal

pattern --ignore-matching-lines pattern

--ignore-case

--paginate

label --label label

--show-c-function

--initial-tab

--expand-tabs

--ignore-all-blanks

number --width number

GFMT

number

--new-file

--unidirectional-new-file

--recursive

name --starting-file name

--report-identical-files

file --exclude-from file

pattern --exclude pattern

a``YY

a``YY,ZZ

d``YY

d``ZZ

c``YY

c``ZZ

c``ZZ,QQ

名称
概要
描述
-C
-c
-D
-e
-f
-n
-q
-U
-u
-y
-a
-B
-b
-d
-I
-i
-l
-L
-p
-T
-t
-w
-W
--changed-group-format
--ignore-file-name-case
--no-ignore-file-name-case
--normal
--speed-large-files
--strip-trailing-cr
--suppress-common-lines
--tabsize
-N
-P
-r
-S
-s
-X
-x
输出风格
XX
XX
XX
XX,YY
XX
XX,YY
XX,YY
文件
退出状态
实例
参见
标准
历史