名字
ln -在文件之间建立连接
总览
ln [options] source [dest]
ln [options] source...directory
POSIX 选项:
[-f]
GNU 选项(缩写):
[-bdfinsvF] [-S backup-suffix] [-V {numbered, existing, simple}] [--help] [--version] [--]
描述
在Unix世界里有两个'link'(连接)概念,一般称之为硬连接和软连接。 一个硬连接仅仅是一个文件名。(一个文件可以有好几个文件名,只有将 最后一个文件名从磁盘上删除,才能把这个文件删掉。文件名的个数是由 ls(1)来确定的。所有的文件名都处于同一个状态,也就没有什么“源名字” 之说。通常文件系统里的一个文件的所有名字包含着一样的数据信息,不 过这样也不是必需的。)一个软连接(或符号连接)是完全不同的:它是 一个包含了路径信息的小小的指定文件。因此,软连接可以指向不同文件 系统里的文件(比如由NFS装载的不同机器文件系统上的文件),甚至可以 指向一个不一定确实存在的文件。在软连接文件被访问(系统调用open(2) 或stat(2))的时候,操作系统用该文件所包含的路径替换该文件的访问介 入点,从而实现对所指文件的访问。(用命令rm(1)和unlink(2)可以删除 连接,但不是删除该文件所指向的文件。系统指定调用lstat(2)和readlink(2) 来读取连接文件与其所指文件的状态。到底是对软连接文件操作,还是对被 指向文件操作,由于不同操作系统件存在不同的系统调用,而存在着差异。) ln 在文件间产生连接。缺省时,产生硬连接,有-s选项,则产生符号(软)连接。 如果仅仅只给出一个文件名,那么ln将在当前目录里产生这个文件的连接,也就是说,以该文件(的最后一个)名称等同的名字在当前目录里产生一个连接(GNU范围内);如果最后一个参数是一个已存在的目录名, ln 将在那个目录里给每一个源文件用以与源文件相同的文件名产生连接,(不同情况见以下--no-dereference的描述);如果只给出两个文件名,ln将产生源文件的连接;如果最后一个参数不是一个目录名或多于两个文件名,则报错。 缺省时,ln不删除已存在的文件或符号连接。(因此,它可以被用来锁定目标文件,即当dest已经不存在时)但选项-f可以强制执行。 在已存在的实现中,只有超级用户才能建立目录的硬连接。 POSIX 禁止系统调用link(2)和ln建立目录的硬连接(但是允许在不同的文件系统间建立硬连接)。
POSIX 选项
- -f
- 删除已存在的目的文件。
GNU 选项
- -d, -F, --directory
- 允许超级用户建立目录硬连接。
- -f, --force
- 删除已存在的目的文件。
- -i, --interactive
- 提示是否删除已存在的目的文件。
- -n, --no-dereference
- 当所给出的目的文件名是一个目录的符号连接时,将其视为一般文件处理。 当目的目录名是一个确实存在的目录(不是一个符号连接)时,不进行模糊处理,而在那个目录里建立连接。但是当所指定的目的目录名是一个符号连接时,有两种方式来对待用户的要求。 ln 会视目的为一个普通目录,并且在里面建立连接。或者如同符号连接本身一样地视其为一个非目录。这种情况下,ln 将在建立新连接之前删除或备份这个符号连接。缺省地,把符号连接视为普通目录来对待。
- -s, --symbolic
- 建立符号连接以替代硬连接。在不支持符号连接的系统上,这个选项仅仅会产生一个错误提示而已。
- -v, --verbose
- 在建立连接前显示所操作的文件名。
GNU 备份选项
对于想备份那些有可能被覆盖、改写或者被破坏的文件, GNU提供了比如:cp, mv, ln, install和patch等命令。可以使用-b参数生成备份文件。备份文件的名称由-V参数指定。假如备份文件的名称是通过原文件名加后缀而得到,那么要用-S参数来指定这个后缀。
- -b, --backup
- 备份文件。
- -S SUFFIX,-suffix=SUFFIX
- 在备份文件后添加"SUFFIX"(你的后缀)。如果不使用该参数,则使用环境变量 SIM_PLE_BACHUP_SUFFIX,如果该环境变量没有设置,则缺省地使用'~'。
- -V METHOD,-version-control=METHOD
- 指定备份文件如何命名。参数"METHOD"可以是'numbered'(或't'),
#p#
NAME
ln - make links between files
SYNOPSIS
ln [OPTION]... TARGET [LINK_NAME]
ln [OPTION]... TARGET... DIRECTORY
ln [OPTION]... --target-directory=DIRECTORY TARGET...
DESCRIPTION
Create a link to the specified TARGET with optional LINK_NAME. If LINK_NAME is omitted, a link with the same basename as the TARGET is created in the current directory. When using the second form with more than one TARGET, the last argument must be a directory; create links in DIRECTORY to each TARGET. Create hard links by default, symbolic links with --symbolic. When creating hard links, each TARGET must exist.
Mandatory arguments to long options are mandatory for short options too.
- --backup[=CONTROL]
- make a backup of each existing destination file
- -b
- like --backup but does not accept an argument
- -d, -F, --directory
- allow the superuser to attempt to hard link directories (note: will probably fail due to system restrictions, even for the superuser)
- -f, --force
- remove existing destination files
- -n, --no-dereference
- treat destination that is a symlink to a directory as if it were a normal file
- -i, --interactive
- prompt whether to remove destinations
- -s, --symbolic
- make symbolic links instead of hard links
- -S, --suffix=SUFFIX
- override the usual backup suffix
- --target-directory=DIRECTORY
- specify the DIRECTORY in which to create the links
- -v, --verbose
- print name of each file before linking
- --help
- display this help and exit
- --version
- output version information and exit
The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX. The version control method may be selected via the --backup option or through the VERSION_CONTROL environment variable. Here are the values:
- none, off
- never make backups (even if --backup is given)
- numbered, t
- make numbered backups
- existing, nil
- numbered if numbered backups exist, simple otherwise
- simple, never
- always make simple backups
AUTHOR
Written by Mike Parker and David MacKenzie.
REPORTING BUGS
Report bugs to <bug-coreutils@gnu.org>.
COPYRIGHT
Copyright © 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
SEE ALSO
The full documentation for ln is maintained as a Texinfo manual. If the info and ln programs are properly installed at your site, the command
- info coreutils ln
should give you access to the complete manual.