'\" te .\" Copyright 1989 AT&T .\" Copyright (c) 2006, 2011, Oracle and/or its affiliates.All rights reserved. .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved .\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation.Original documentation from The Open Group can be obtained online at http://www.opengroup.org/bookstore/. .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation.In the following statement, the phrase "this text" refers to portions of the system documentation.Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document.The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.This notice shall appear on any product containing this material. .TH cmp 1 "2011 年 7 月 25 日" "SunOS 5.11" "用户命令" .SH 名称 cmp \- 比较两个文件 .SH 用法概要 .LP .nf \fB/usr/bin/cmp\fR [\fB-l\fR | \fB-s\fR] \fIfile1\fR \fIfile2\fR [\fIskip1\fR] [\fIskip2\fR] .fi .SH 描述 .sp .LP \fBcmp\fR 可比较两个文件 \fIfile1\fR 和 \fIfile2\fR。如果两个文件相同,则 \fBcmp\fR 不写入任何输出。缺省情况下,如果两个文件不同,会将出现第一处差异的字节号和行号写入标准输出。字节和行的编号都从 \fB1\fR 开始。 .sp .LP \fIskip1\fR 和 \fIskip2\fR 分别是 \fIfile1\fR 和 \fIfile2\fR 的初始字节偏移量,可以是八进制或十进制。前导 \fB0\fR 表示八进制。 .sp .LP 如果 \fIfile1\fR 或 \fIfiles2\fR 为 \fB-\fR,\fBcmp\fR 将使用该操作数的标准输入。 .SH 选项 .sp .LP 支持以下选项: .sp .ne 2 .mk .na \fB\fB-l\fR\fR .ad .RS 6n .rt 写入每处差异的十进制字节号和不同的字节(八进制)。 .RE .sp .ne 2 .mk .na \fB\fB-s\fR\fR .ad .RS 6n .rt 对于不同文件,不写入任何内容。仅返回\fB非零\fR退出状态。 .RE .SH 操作数 .sp .LP 支持下列操作数: .sp .ne 2 .mk .na \fB\fIfile1\fR\fR .ad .RS 9n .rt 要比较的第一个文件的路径名。如果 \fIfile1\fR 为 \fB-\fR,则使用标准输入。 .RE .sp .ne 2 .mk .na \fB\fIfile2\fR\fR .ad .RS 9n .rt 要比较的第二个文件的路径名。如果 \fIfile2\fR 为 \fB-\fR,则使用标准输入。 .RE .sp .LP 如果 \fIfile1\fR 和 \fIfile2\fR 均引用标准输入或引用同一 \fBFIFO\fR 特殊文件、块特殊文件或字符特殊文件,会出现错误。 .SH 用法 .sp .LP 有关 \fBcmp\fR 遇到大于或等于 2 GB(2^31 字节)文件时行为的说明,请参见 \fBlargefile\fR(5)。 .SH 示例 .LP \fB示例 1 \fR逐字节比较文件 .sp .LP 以下示例将对 \fIfile1\fR 和 \fIfile2\fR 进行逐字节比较: .sp .in +2 .nf example% cmp file1 file2 0 1024 .fi .in -2 .sp .sp .LP 开始比较前,将跳过 \fIfile2\fR 中的前 1024 字节。 .SH 环境变量 .sp .LP 有关影响 \fBcmp\fR 执行的以下环境变量的说明,请参见 \fBenviron\fR(5):\fBLANG\fR、\fBLC_ALL\fR、\fBLC_CTYPE\fR、\fBLC_MESSAGES\fR 和 \fBNLSPATH\fR。 .SH 退出状态 .sp .LP 将返回以下错误值: .sp .ne 2 .mk .na \fB\fB0\fR\fR .ad .RS 6n .rt 文件相同。 .RE .sp .ne 2 .mk .na \fB\fB1\fR\fR .ad .RS 6n .rt 文件不同。其中包括一个文件与另一个文件的前一部分相同的情况。 .RE .sp .ne 2 .mk .na \fB\fB>1\fR\fR .ad .RS 6n .rt 出现错误。 .RE .SH 属性 .sp .LP 有关下列属性的说明,请参见 \fBattributes\fR(5): .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . 属性类型属性值 _ 可用性system/core-os _ CSIEnabled(已启用) _ 接口稳定性Committed(已确定) _ 标准请参见 \fBstandards\fR(5)。 .TE .SH 另请参见 .sp .LP \fBcomm\fR(1)、\fBdiff\fR(1)、\fBattributes\fR(5)、\fBenviron\fR(5)、\fBlargefile\fR(5)、\fBstandards\fR(5)