'\" te .\" Copyright 1989 AT&T .\" Copyright (c) 1992, X/Open Company Limited All Rights Reserved .\" Copyright (c) 2006, 2010, Oracle and/or its affiliates.All rights reserved. .\" 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 file 1 "2010 年 12 月 8 日" "SunOS 5.11" "用户命令" .SH 名称 file \- 确定文件类型 .SH 用法概要 .LP .nf \fB/usr/bin/file\fR [\fB-dh\fR] [\fB-m\fR \fImfile\fR] [\fB-M\fR \fIMfile\fR] [\fB-f\fR \fIffile\fR] \fIfile\fR... .fi .LP .nf \fB/usr/bin/file\fR [\fB-dh\fR] [\fB-m\fR \fImfile\fR] [\fB-M\fR \fIMfile\fR] \fB-f\fR \fIffile\fR .fi .LP .nf \fB/usr/bin/file\fR \fB-i\fR [\fB-h\fR] [\fB-f\fR \fIffile\fR] \fIfile\fR... .fi .LP .nf \fB/usr/bin/file\fR \fB-i\fR [\fB-h\fR] \fB-f\fR \fIffile\fR .fi .LP .nf \fB/usr/bin/file\fR \fB-c\fR [\fB-d\fR] [\fB-m\fR \fImfile\fR] [\fB-M\fR \fIMfile\fR] .fi .LP .nf \fB/usr/xpg4/bin/file\fR [\fB-dh\fR] [\fB-m\fR \fImfile\fR] [\fB-M\fR \fIMfile\fR] [\fB-f\fR \fIffile\fR] \fIfile\fR... .fi .LP .nf \fB/usr/xpg4/bin/file\fR [\fB-dh\fR] [\fB-m\fR \fImfile\fR] [\fB-M\fR \fIMfile\fR] \fB-f\fR \fIffile\fR .fi .LP .nf \fB/usr/xpg4/bin/file\fR \fB-i\fR [\fB-h\fR] [\fB-f\fR \fIffile\fR] \fIfile\fR... .fi .LP .nf \fB/usr/xpg4/bin/file\fR \fB-i\fR [\fB-h\fR] \fB-f\fR \fIffile\fR .fi .LP .nf \fB/usr/xpg4/bin/file\fR \fB-c\fR [\fB-d\fR] [\fB-m\fR \fImfile\fR] [\fB-M\fR \fIMfile\fR] .fi .SH 描述 .sp .LP \fBfile\fR 实用程序可对 \fIfile\fR 提供的每个文件执行一系列测试,也可以对 \fIffile\fR 中列出的每个文件进行测试,以尝试将其分类。如果该文件不是一个常规文件,则会标识其文件类型。文件类型目录、\fBFIFO\fR、块特殊文件和字符特殊文件就是这样标识的。如果文件是常规文件并且长度为零,将标识为空文件。 .sp .LP 如果 \fIfile\fR 看起来是文本文件,\fBfile\fR 将检查第一个 512 字节并尝试确定其编程语言。如果 \fIfile\fR 是符号链接,缺省情况下将遵循该链接,\fBfile\fR 将测试符号链接所指向的文件。 .sp .LP 如果 \fIfile\fR 是可重定位目标文件、可执行文件或共享目标文件,\fBfile\fR 将输出有关该文件的执行要求的信息。此信息包括机器类、字节排序、静态/动态链接以及任何软件或硬件功能要求。如果 \fIfile\fR 是运行时链接配置文件,\fBfile\fR 将列显有关目标平台的信息,包括机器类和字节排序。 .sp .LP 缺省情况下,\fBfile\fR 将尝试使用本地化的幻数文件 \fB/usr/lib/locale/\fIlocale\fR/LC_MESSAGES/magic\fR(如果存在)来标识具有幻数的文件。例如,在日文语言环境中,\fBfile\fR 将尝试使用 \fB/usr/lib/locale/ja/LC_MESSAGES/magic\fR。如果不存在本地化的幻数文件,\fBfile\fR 将使用 \fB/etc/magic\fR。幻数是表示文件类型的数字或字符串常量。有关 \fB/etc/magic\fR 格式的说明,请参见 \fBmagic\fR(4)。 .sp .LP 如果 \fIfile\fR 不存在、无法读取或无法确定其文件状态,不会将其视为错误而影响退出状态。输出将指示该文件已处理,但无法确定其类型。 .SH 选项 .sp .LP 支持以下选项: .sp .ne 2 .mk .na \fB\fB-c\fR\fR .ad .RS 12n .rt 检查幻数文件的格式错误。出于效率的原因,通常不会进行此验证。 .RE .sp .ne 2 .mk .na \fB\fB-d\fR\fR .ad .RS 12n .rt 对文件执行任何位置敏感和上下文敏感的缺省系统测试。 .RE .sp .ne 2 .mk .na \fB\fB-f\fR \fIffile\fR\fR .ad .RS 12n .rt \fIffile\fR 包含要检查的文件列表。 .RE .sp .ne 2 .mk .na \fB\fB-h\fR\fR .ad .RS 12n .rt 遇到符号链接时,此选项会将该文件标识为符号链接。如果未指定 \fB-h\fR,并且 \fIfile\fR 是指向不存在的文件的符号链接,则 \fBfile\fR 实用程序会将该文件标识为符号链接,就像已指定 \fB-h\fR 一样。 .RE .sp .ne 2 .mk .na \fB\fB-i\fR\fR .ad .RS 12n .rt 如果文件是常规文件,此选项不会尝试进一步区分文件类型,而是将该文件标识为“常规文件”。 .RE .sp .ne 2 .mk .na \fB\fB-m\fR \fImfile\fR\fR .ad .RS 12n .rt .sp .ne 2 .mk .na \fB\fB/usr/bin/file\fR\fR .ad .RS 22n .rt 将 \fImfile\fR 而非 \fB/etc/magic\fR 用作备用幻数文件。 .RE .sp .ne 2 .mk .na \fB\fB/usr/xpg4/bin/file\fR\fR .ad .RS 22n .rt 指定包含位置敏感测试的文件的名称,这些测试将应用于文件以将其分类(请参见 \fBmagic\fR(4))。如果已指定 \fB-m\fR 选项但未指定 \fB-d\fR 选项或 \fB-M\fR 选项,则执行 \fB-m\fR 选项指定的位置敏感测试后将应用位置敏感的缺省系统测试。 .RE .RE .sp .ne 2 .mk .na \fB\fB-M\fR \fIMfile\fR\fR .ad .RS 12n .rt 指定包含位置敏感测试的文件的名称,这些测试将应用于文件以将其分类(请参见 \fBmagic\fR(4))。只有在同时指定了 \fB-d\fR 选项时,才会应用位置敏感的缺省系统测试或上下文敏感的缺省系统测试。 .RE .sp .LP 如果同时指定了 \fB-M\fR 选项与 \fB-d\fR 选项和/或 \fB-m\fR 选项,或者同时指定了 \fB-m\fR 选项与 \fB-d\fR 选项,将按照这些选项的出现顺序,依次连续地应用由这些选项所指定的位置敏感测试。 .SH 操作数 .sp .LP 支持下列操作数: .sp .ne 2 .mk .na \fB\fIfile\fR\fR .ad .RS 8n .rt 要测试的文件的路径名。 .RE .SH 用法 .sp .LP 有关 \fBfile\fR 遇到大于或等于 2 GB(2^31 字节)文件时行为的说明,请参见 \fBlargefile\fR(5)。 .SH 示例 .LP \fB示例 1 \fR确定参数是否为二进制可执行文件 .sp .LP 以下示例将确定参数是否为二进制可执行文件: .sp .in +2 .nf file "$1" | grep \(miFq executable && printf "%s is executable.\en" "$1" .fi .in -2 .sp .SH 环境变量 .sp .LP 有关影响 \fBfile\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\fB>0\fR\fR .ad .RS 6n .rt 出现错误。 .RE .SH 文件 .sp .ne 2 .mk .na \fB\fB/etc/magic\fR\fR .ad .RS 14n .rt \fBfile\fR 的幻数文件 .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 \fBcrle\fR(1)、\fBelfdump\fR(1)、\fBelffile\fR(1)、\fBls\fR(1)、\fBmagic\fR(4)、\fBattributes\fR(5)、\fBenviron\fR(5)、\fBlargefile\fR(5)、\fBstandards\fR(5) .SH 附注 .sp .LP \fBfile\fR 实用程序无法检查归档成员,除非先将这些成员从归档中提取到单独文件中。\fBelffile\fR 实用程序可以就地检查归档成员,建议与 \fBELF\fR 目标文件和归档文件一起使用。