'\" te .\" Copyright (c) 1992, X/Open Company Limited All Rights Reserved Portions Copyright (c) 1996, Sun Microsystems, Inc. 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 pathchk 1 "1995 年 2 月 1 日" "SunOS 5.11" "用户命令" .SH 名称 pathchk \- 检查路径名 .SH 用法概要 .LP .nf \fBpathchk\fR [\fB-p\fR] \fIpath\fR... .fi .SH 描述 .sp .LP \fBpathchk\fR 命令将检查一个或多个路径名是否有效(即能够在不导致语法错误的情况下用于访问或创建文件)且可移植(即不会造成任何文件名截断)。更丰富的可移植性检查由 \fB-p\fR 选项提供。 .sp .LP 缺省情况下,\fBpathchk\fR 将基于底层文件系统检查各 \fIpath\fR 操作数的各个组件。将针对每个 \fIpath\fR 操作数写入诊断: .RS +4 .TP .ie t \(bu .el o 长度大于 \fIPATH_MAX\fR 字节。 .RE .RS +4 .TP .ie t \(bu .el o 父目录中包含长度大于 \fINAME_MAX\fR 字节的任意组件 .RE .RS +4 .TP .ie t \(bu .el o 包含不可搜索的目录中的任意组件 .RE .RS +4 .TP .ie t \(bu .el o 包含在父目录中无效的任意组件的任意字符。 .RE .sp .LP 未指定诊断消息的格式,但将指示检测到的错误和对应的 \fIpath\fR 操作数。 .sp .LP 只要可以创建与缺失组件指定的路径名匹配的文件且不违反上面指定的任意检查项,即便 \fIpath\fR 操作数的一个或多个组件不存在,也不应视为错误。 .SH 选项 .sp .LP 支持以下选项: .sp .ne 2 .mk .na \fB\fB-p\fR\fR .ad .RS 6n .rt 不基于底层文件系统执行检查,而是针对每个 \fIpath\fR 操作数写入诊断: .RS +4 .TP .ie t \(bu .el o 长度大于 \fB_POSIX_PATH_MAX \fR 字节 .RE .RS +4 .TP .ie t \(bu .el o 包含长度大于 \fB_POSIX_NAME_MAX\fR 字节的任意组件 .RE .RS +4 .TP .ie t \(bu .el o 包含不在可移植文件名字符集中的任意组件的任意字符。 .RE .RE .SH 操作数 .sp .LP 支持下列操作数: .sp .ne 2 .mk .na \fB\fIpath\fR\fR .ad .RS 8n .rt 要检查的路径。 .RE .SH 用法 .sp .LP 有关 \fBpathchk\fR 遇到大于或等于 2 GB(2^31 字节)文件时行为的说明,请参见 \fBlargefile\fR(5)。 .SH 示例 .LP \fB示例 1 \fR使用 pathchk 命令 .sp .LP 验证导入的数据交换归档中的所有路径是否在当前系统上均合法而且明确: .sp .in +2 .nf example% \fBpax -f archive | sed -e '/ == .*/s///' | xargs pathchk if [ $? -eq 0 ] then pax -r -f archive else echo Investigate problems before importing files. exit 1 fi\fR .fi .in -2 .sp .sp .LP 验证当前目录分层结构中的所有文件是否均可移动到遵循 X/Open 规范且支持 \fBpax\fR(1) 命令的任意系统: .sp .in +2 .nf example% \fBfind . -print | xargs pathchk -p if [ $? \(mieq 0 ] then pax -w -f archive . else echo Portable archive cannot be created. exit 1 fi\fR .fi .in -2 .sp .sp .LP 验证用户提供的路径是否指定可读文件,应用程序是否能够在不截断也不覆盖任何现有文件的情况下创建扩展给定路径的文件: .sp .in +2 .nf example% \fBcase $- in *C*) reset="";; *) reset="set +C" set -C;; esac test -r "$path" && pathchk "$path.out" && rm "$path.out" > "$path.out" if [ $? -ne 0 ]; then printf "%s: %s not found or %s.out fails \e creation checks.\en" $0 "$path" "$path" $reset # reset the noclobber option in case a trap # on EXIT depends on it exit 1 fi $reset PROCESSING < "$path" > "$path.out"\fR .fi .in -2 .sp .sp .LP 本示例中做出了以下假设: .RS +4 .TP 1. \fBPROCESSING\fR 表示应用程序在确认 \fB$path.out\fR 按预期运行后使用 \fB$path\fR 需要使用的代码。 .RE .RS +4 .TP 2. 调用此代码时 \fBnoclobber\fR 选项的状态未知,调用此代码时应将其设置为退出时恢复其原来所处的状态。(本示例中使用 \fBreset\fR 变量恢复初始状态。) .RE .RS +4 .TP 3. 注意以下用法: .sp .in +2 .nf \fBrm "$path.out" > "$path.out"\fR .fi .in -2 .sp .sp .ne 2 .mk .na \fBa.\fR .ad .RS 6n .rt 已验证 \fBpathchk\fR 命令,此时将不会截断 \fB$path.out\fR。 .RE .sp .ne 2 .mk .na \fBb.\fR .ad .RS 6n .rt 设置 \fBnoclobber\fR 选项后,shell 将首先验证是否已不存在 \fB$path.out\fR,然后再调用 \fBrm\fR。 .RE .sp .ne 2 .mk .na \fBc.\fR .ad .RS 6n .rt 如果 shell 已成功创建 \fB$path.out\fR,\fBrm\fR 会将其删除,这样应用程序就能在 \fBPROCESSING\fR 步骤中重新创建该文件。 .RE .sp .ne 2 .mk .na \fBd.\fR .ad .RS 6n .rt 如果 \fBPROCESSING\fR 步骤希望在其调用时该文件已经存在,那么: .sp .in +2 .nf \fBrm "$path.out" > "$path.out"\fR .fi .in -2 .sp 应替换为: .sp .in +2 .nf \fB> "$path.out"\fR .fi .in -2 .sp 它将验证是否已不存在该文件,但保留 \fB$path.out\fR 供 \fBPROCESSING\fR 使用。 .RE .RE .SH 环境变量 .sp .LP 有关影响 \fBpathchk\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 所有 \fIpath\fR 操作数均已通过所有检查。 .RE .sp .ne 2 .mk .na \fB\fB>0\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 _ 接口稳定性Committed(已确定) _ 标准请参见 \fBstandards\fR(5)。 .TE .SH 另请参见 .sp .LP \fBpax\fR(1)、\fBtest\fR(1)、\fBattributes\fR(5)、\fBenviron\fR(5)、\fBlargefile\fR(5)、\fBstandards\fR(5)