1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\" 1993 Michael Haardt, Ian Jackson.
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" Modified 1993-07-23 by Rik Faith <faith@cs.unc.edu>
27 .\" Modified 1994-08-21 by Michael Haardt
28 .\" Modified 2004-06-23 by Michael Kerrisk <mtk-manpages@gmx.net>
29 .\" Modified 2005-04-04, as per suggestion by Michael Hardt for rename.2
31 .TH LINK 2 2004-06-23 "Linux 2.6.7" "Linux Programmer's Manual"
33 link \- make a new name for a file
35 .B #include <unistd.h>
37 .BI "int link(const char *" oldpath ", const char *" newpath );
40 creates a new link (also known as a hard link) to an existing file.
48 This new name may be used exactly as the old one for any operation;
49 both names refer to the same file (and so have the same permissions
50 and ownership) and it is impossible to tell which name was the
53 On success, zero is returned.
54 On error, \-1 is returned, and
60 Write access to the directory containing
62 is denied, or search permission is denied for one of the directories
68 .BR path_resolution (2).)
75 .IR oldpath " or " newpath " points outside your accessible address space."
78 An I/O error occurred.
81 Too many symbolic links were encountered in resolving
82 .IR oldpath " or " newpath .
85 The file referred to by
87 already has the maximum number of links to it.
90 .IR oldpath " or " newpath " was too long."
93 A directory component in
94 .IR oldpath " or " newpath
95 does not exist or is a dangling symbolic link.
98 Insufficient kernel memory was available.
101 The device containing the file has no room for the new directory
105 A component used as a directory in
106 .IR oldpath " or " newpath
107 is not, in fact, a directory.
114 The filesystem containing
115 .IR oldpath " and " newpath
116 does not support the creation of hard links.
119 The file is on a read-only filesystem.
122 .IR oldpath " and " newpath
123 are not on the same mounted filesystem.
124 (Linux permits a filesystem to be mounted at multiple points, but
126 does not work across different mount points,
127 even if the same filesystem is mounted on both.)
129 Hard links, as created by
131 cannot span filesystems.
136 POSIX.1-2001 says that
140 if it is a symbolic link.
141 However, Linux does not do so: if
143 is a symbolic link, then
145 is created as a (hard) link to the same symbolic link file
148 becomes a symbolic link to the same file that
151 Some other implementations behave in the same manner as Linux.
152 .\" For example, the default Solaris compilation environment
153 .\" behaves like Linux, and contributors to a March 2005
154 .\" thread in the Austin mailing list reported that some
155 .\" other (System V) implementations did/do the same -- MTK, Apr 05
157 SVr4, 4.3BSD, POSIX.1-2001 (except as noted above).
158 .\" SVr4 documents additional ENOLINK and
159 .\" EMULTIHOP error conditions; POSIX.1 does not document ELOOP.
160 .\" X/OPEN does not document EFAULT, ENOMEM or EIO.
162 On NFS file systems, the return code may be wrong in case the NFS server
163 performs the link creation and dies before it can say so.
166 to find out if the link got created.
171 .BR path_resolution (2),