1 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
2 .\" and Copyright (C) 1993 Michael Haardt, Ian Jackson.
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" 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@gmail.com>
29 .\" Modified 2005-04-04, as per suggestion by Michael Hardt for rename.2
31 .TH LINK 2 2013-01-27 "Linux" "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 (7).)
71 The user's quota of disk blocks on the file system has been exhausted.
78 .IR oldpath " or " newpath " points outside your accessible address space."
81 An I/O error occurred.
84 Too many symbolic links were encountered in resolving
85 .IR oldpath " or " newpath .
88 The file referred to by
90 already has the maximum number of links to it.
93 .IR oldpath " or " newpath " was too long."
96 A directory component in
97 .IR oldpath " or " newpath
98 does not exist or is a dangling symbolic link.
101 Insufficient kernel memory was available.
104 The device containing the file has no room for the new directory
108 A component used as a directory in
109 .IR oldpath " or " newpath
110 is not, in fact, a directory.
117 The file system containing
118 .IR oldpath " and " newpath
119 does not support the creation of hard links.
121 .BR EPERM " (since Linux 3.6)"
122 The caller does not have permission to create a hard link to this file
123 (see the description of
124 .IR /proc/sys/fs/protected_hardlink
129 The file is on a read-only file system.
132 .IR oldpath " and " newpath
133 are not on the same mounted file system.
134 (Linux permits a file system to be mounted at multiple points, but
136 does not work across different mount points,
137 even if the same file system is mounted on both.)
139 SVr4, 4.3BSD, POSIX.1-2001 (but see NOTES).
140 .\" SVr4 documents additional ENOLINK and
141 .\" EMULTIHOP error conditions; POSIX.1 does not document ELOOP.
142 .\" X/OPEN does not document EFAULT, ENOMEM or EIO.
144 Hard links, as created by
146 cannot span file systems.
151 POSIX.1-2001 says that
155 if it is a symbolic link.
156 However, since kernel 2.0,
157 .\" more precisely: since kernel 1.3.56
158 Linux does not do so: if
160 is a symbolic link, then
162 is created as a (hard) link to the same symbolic link file
165 becomes a symbolic link to the same file that
168 Some other implementations behave in the same manner as Linux.
169 .\" For example, the default Solaris compilation environment
170 .\" behaves like Linux, and contributors to a March 2005
171 .\" thread in the Austin mailing list reported that some
172 .\" other (System V) implementations did/do the same -- MTK, Apr 05
173 POSIX.1-2008 changes the specification of
175 making it implementation-dependent whether or not
177 is dereferenced if it is a symbolic link.
178 For precise control over the treatment of symbolic links when
182 On NFS file systems, the return code may be wrong in case the NFS server
183 performs the link creation and dies before it can say so.
186 to find out if the link got created.
195 .BR path_resolution (7),