'\" te .\" Copyright 1989 AT&T .\" Copyright (c) 2004, Sun Microsystems, Inc. All Rights Reserved .\" Portions Copyright (c) 1992, X/Open Company Limited 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 ln 1 "2004 年 3 月 25 日" "SunOS 5.11" "用户命令" .SH 名称 ln \- 创建文件的硬链接或符号链接 .SH 用法概要 .LP .nf \fB/usr/bin/ln\fR [\fB-fns\fR] \fIsource_file\fR [\fItarget\fR] .fi .LP .nf \fB/usr/bin/ln\fR [\fB-fns\fR] \fIsource_file\fR... \fItarget\fR .fi .LP .nf \fB/usr/xpg4/bin/ln\fR [\fB-fs\fR] \fIsource_file\fR [\fItarget\fR] .fi .LP .nf \fB/usr/xpg4/bin/ln\fR [\fB-fs\fR] \fIsource_file\fR... \fItarget\fR .fi .SH 描述 .sp .LP 在第一个概要形式中,\fBln\fR 实用程序为 \fIsource_file\fR 指定的文件在 \fItarget\fR 指定的目标路径位置创建新的目录条目(链接)。如果未指定 \fItarget\fR,则将在当前目录中设置链接。当最终操作数不指定现有目录时,将假定使用第一个概要形式;如果指定的操作数超过两个且最后一个不是现有目录,则会导致错误。 .sp .LP 在第二个概要形式中,\fBln\fR 实用程序将为 \fIsource_file\fR 操作数指定的每个文件在由 \fItarget\fR 指定的现有目录中的目标路径位置创建新的目录条目。 .sp .LP \fBln\fR 实用程序可用于创建硬链接和符号链接。硬链接是文件的指针,与原始目录条目无法区分。对文件所做的任何更改都是有效的,并不依赖用于引用文件的名称。硬链接不能跨文件系统而且不能引用目录。 .sp .LP 缺省情况下,\fBln\fR 将创建硬链接。\fIsource_file\fR 将链接到 \fItarget\fR。如果 \fItarget\fR 是一个目录,则会在 \fItarget\fR 中创建另一个名为 \fIsource_file\fR 的文件,并链接到原始 \fIsource_file\fR。 .sp .LP 如果 \fItarget\fR 是现有文件且未指定 \fB-f\fR 选项,则 \fBln\fR 会将诊断消息写入标准错误,不对当前 \fIsource_file\fR 执行任何其他操作,然后继续转到其余的 \fIsource_file\fR。 .sp .LP 符号链接是文件的间接指针,其目录条目包含所链接到的文件名称。符号链接可以跨文件系统而且可以引用目录。 .sp .LP \fItarget\fR 的文件权限与显示为 \fB-l\fR 的 \fBls\fR(1) 命令列表的权限有所不同。要显示 \fItarget\fR 的权限,请使用 \fBls\fR \fB-lL\fR。有关详细信息,请参见 \fBstat\fR(2)。 .SS "/usr/bin/ln" .sp .LP 如果 \fB/usr/bin/ln\fR 确定 \fItarget\fR 的模式禁止写入,则会列显该模式(请参见 \fBchmod\fR(1)),并请求响应,然后读取一行的标准输入。如果响应是肯定性的,并且权限允许,则链接生效。否则,命令将退出。 .SS "/usr/xpg4/bin/ln" .sp .LP 当创建硬链接且源文件本身为符号链接时,目标将是一个硬链接,链接到由符号链接所引用的文件,而不是链接到符号链接对象本身(\fIsource_file\fR)。 .SH 选项 .sp .LP \fB/usr/bin/ln\fR 和 \fB/usr/xpg4/bin/ln\fR 支持以下选项: .sp .ne 2 .mk .na \fB\fB-f\fR\fR .ad .RS 6n .rt 不询问用户的链接文件,即使在 \fItarget\fR 禁止写入模式中也同样如此。如果标准输入不是终端,则此为缺省选项。 .RE .sp .ne 2 .mk .na \fB\fB-s\fR\fR .ad .RS 6n .rt 创建符号链接。 .sp 如果 \fB-s\fR 选项与两个参数结合使用,则 \fItarget\fR 可能为现有目录或不存在的文件。如果 \fItarget\fR 已经存在并且不是目录,则会返回错误。\fIsource_file\fR 可能是任何路径名,并不需要存在。如果存在,可能是文件或目录,并且可能驻留在与 \fItarget\fR 不同的文件系统中。如果 \fItarget\fR 是现有目录,则会在名为 \fIsource_file\fR 或名称为 \fIsource_file\fR 最后组成部分的目录 \fItarget\fR 中创建文件。此文件是引用 \fIsource_file\fR 的符号链接。如果 \fItarget\fR 不存在,则将创建名为 \fItarget\fR 的文件,该文件是引用 \fIsource_file\fR 的符号链接。 .sp 如果 \fB-s\fR 选项与超过两个参数一起使用,则 \fItarget\fR 必须是现有目录,否则会返回错误。对于每个 \fIsource_file\fR,将在名称为 \fIsource_file\fR 最后组成部分的 \fItarget\fR 中创建链接。每个新 \fIsource_file\fR 都是原始 \fIsource_file\fR 的符号链接。文件和 \fI target\fR 可能驻留在不同的文件系统中。 .RE .SS "/usr/bin/ln" .sp .LP \fB/usr/bin/ln\fR 仅支持以下选项: .sp .ne 2 .mk .na \fB\fB-n\fR\fR .ad .RS 6n .rt 如果 \fItarget\fR 是现有文件,则将诊断消息写入标准错误中,然后继续转到其余的 \fIsource_file\fR。\fB-f\fR 选项可覆盖此选项。此为 \fB/usr/bin/ln\fR 和 \fB/usr/xpg4/bin/ln\fR 的缺省行为,并在无提示的情况下被忽略。 .RE .SH 操作数 .sp .LP 支持下列操作数: .sp .ne 2 .mk .na \fB\fIsource_file\fR\fR .ad .RS 15n .rt 要链接的文件的路径名。可以是常规文件或特殊文件。如果指定了 \fB-s\fR 选项,则 \fIsource_file\fR 也可以是目录。 .RE .sp .ne 2 .mk .na \fB\fItarget\fR\fR .ad .RS 15n .rt 要创建的新目录条目的路径名,或者要在其中创建新目录条目的现有目录的路径名。 .RE .SH 用法 .sp .LP 有关 \fBln\fR 遇到大于或等于 2 GB(2^31 字节)文件时行为的说明,请参见 \fBlargefile\fR(5)。 .SH 环境变量 .sp .LP 有关影响 \fBln\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 .LP 有关下列属性的说明,请参见 \fBattributes\fR(5): .SS "/usr/bin/ln" .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . 属性类型属性值 _ 可用性system/core-os _ CSIEnabled(已启用) .TE .SS "/usr/xpg4/bin/ln" .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . 属性类型属性值 _ 可用性system/xopen/xcu4 _ CSIEnabled(已启用) _ 接口稳定性Committed(已确定) _ 标准请参见 \fBstandards\fR(5)。 .TE .SH 另请参见 .sp .LP \fBchmod\fR(1)、\fBls\fR(1)、\fBstat\fR(2)、\fBattributes\fR(5)、\fBenviron\fR(5)、\fBlargefile\fR(5)、\fBstandards\fR(5) .SH 附注 .sp .LP 链接到目录的符号链接在某些情况下的行为可能与您的预期有所不同。针对此链接使用 \fBls\fR(1) 命令可显示所指向的目录中的文件,而输入 \fBls\fR \fB-l\fR 则显示有关链接本身的信息。 .sp .in +2 .nf example% \fBln -s dir link\fR example% \fBls link\fR file1 file2 file3 file4 example% \fBls -l link\fR lrwxrwxrwx 1 user 7 Jan 11 23:27 link -> dir .fi .in -2 .sp .sp .LP 当使用 \fB/usr/bin/sh\fR 或 \fB/usr/bin/csh\fR 通过符号链接转到一个目录时(请参见 \fBcd\fR(1)),将停止于文件系统内所指向的位置。这意味着新工作目录的父项不是符号链接的父项,而是所指向目录的父项。将 \fBcd\fR 与 \fB/usr/bin/ksh\fR 或 \fB/usr/xpg4/bin/sh\fR 中的 \fB-P\fR 选项结合使用时也会出现此情况。例如,在以下情况中,最终工作目录是 \fB/usr\fR 而不是 \fB/home/user/linktest\fR。 .sp .in +2 .nf example% \fBpwd\fR /home/user/linktest example% \fBln -s /usr/tmp symlink\fR example% \fBcd symlink\fR example% \fBcd .\|.\fR example% \fBpwd\fR /usr .fi .in -2 .sp .sp .LP C shell 用户通过使用 \fBpushd\fR 和 \fBpopd\fR 内置命令来代替 \fBcd\fR 可避免产生任何导航问题。