1 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
2 .\" and Copyright (C) 1993 Michael Haardt, Ian Jackson.
3 .\" and Copyright (C) 2006, 2014 Michael Kerrisk
5 .\" %%%LICENSE_START(VERBATIM)
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.
27 .\" Modified 1993-07-23 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified 1994-08-21 by Michael Haardt
29 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
30 .\" Modified 2005-04-04, as per suggestion by Michael Hardt for rename.2
32 .TH LINK 2 2014-08-19 "Linux" "Linux Programmer's Manual"
34 link, linkat \- make a new name for a file
37 .B #include <unistd.h>
39 .BI "int link(const char *" oldpath ", const char *" newpath );
41 .BR "#include <fcntl.h> " "/* Definition of AT_* constants */"
42 .B #include <unistd.h>
44 .BI "int linkat(int " olddirfd ", const char *" oldpath ,
45 .BI " int " newdirfd ", const char *" newpath ", int " flags );
49 Feature Test Macro Requirements for glibc (see
50 .BR feature_test_macros (7)):
59 _XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L
68 creates a new link (also known as a hard link) to an existing file.
76 This new name may be used exactly as the old one for any operation;
77 both names refer to the same file (and so have the same permissions
78 and ownership) and it is impossible to tell which name was the
83 system call operates in exactly the same way as
85 except for the differences described here.
87 If the pathname given in
89 is relative, then it is interpreted relative to the directory
90 referred to by the file descriptor
92 (rather than relative to the current working directory of
93 the calling process, as is done by
95 for a relative pathname).
105 is interpreted relative to the current working
106 directory of the calling process (like
115 The interpretation of
119 except that a relative pathname is interpreted relative
120 to the directory referred to by the file descriptor
123 The following values can be bitwise ORed in
126 .BR AT_EMPTY_PATH " (since Linux 2.6.39)"
127 .\" commit 11a7b371b64ef39fc5fb1b6f2218eef7c4d035e3
130 is an empty string, create a link to the file referenced by
132 (which may have been obtained using the
138 can refer to any type of file, not just a directory.
139 This will generally not work if the file has a link count of zero (files
145 The caller must have the
146 .BR CAP_DAC_READ_SEARCH
147 capability in order to use this flag.
148 This flag is Linux-specific; define
150 .\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
151 to obtain its definition.
153 .BR AT_SYMLINK_FOLLOW " (since Linux 2.6.18)"
158 if it is a symbolic link (like
166 to be dereferenced if it is a symbolic link.
167 If procfs is mounted,
168 this can be used as an alternative to
174 linkat(AT_FDCWD, "/proc/self/fd/<fd>", newdirfd,
175 newname, AT_SYMLINK_FOLLOW);
179 Before kernel 2.6.18, the
181 argument was unused, and had to be specified as 0.
185 for an explanation of the need for
188 On success, zero is returned.
189 On error, \-1 is returned, and
191 is set appropriately.
195 Write access to the directory containing
197 is denied, or search permission is denied for one of the directories
198 in the path prefix of
203 .BR path_resolution (7).)
206 The user's quota of disk blocks on the filesystem has been exhausted.
213 .IR oldpath " or " newpath " points outside your accessible address space."
216 An I/O error occurred.
219 Too many symbolic links were encountered in resolving
220 .IR oldpath " or " newpath .
223 The file referred to by
225 already has the maximum number of links to it.
228 .IR oldpath " or " newpath " was too long."
231 A directory component in
232 .IR oldpath " or " newpath
233 does not exist or is a dangling symbolic link.
236 Insufficient kernel memory was available.
239 The device containing the file has no room for the new directory
243 A component used as a directory in
244 .IR oldpath " or " newpath
245 is not, in fact, a directory.
252 The filesystem containing
253 .IR oldpath " and " newpath
254 does not support the creation of hard links.
256 .BR EPERM " (since Linux 3.6)"
257 The caller does not have permission to create a hard link to this file
258 (see the description of
259 .IR /proc/sys/fs/protected_hardlinks
264 The file is on a read-only filesystem.
267 .IR oldpath " and " newpath
268 are not on the same mounted filesystem.
269 (Linux permits a filesystem to be mounted at multiple points, but
271 does not work across different mount points,
272 even if the same filesystem is mounted on both.)
274 The following additional errors can occur for
281 is not a valid file descriptor.
284 An invalid flag value was specified in
291 but the caller did not have the
292 .B CAP_DAC_READ_SEARCH
296 An attempt was made to link to the
298 file corresponding to a file descriptor created with
300 open(path, O_TMPFILE | O_EXCL, mode);
307 is a relative pathname and
309 refers to a directory that has been deleted,
312 is a relative pathname and
314 refers to a directory that has been deleted.
320 is a file descriptor referring to a file other than a directory;
331 is an empty string, and
333 refers to a directory.
336 was added to Linux in kernel 2.6.16;
337 library support was added to glibc in version 2.4.
340 SVr4, 4.3BSD, POSIX.1-2001 (but see NOTES), POSIX.1-2008.
341 .\" SVr4 documents additional ENOLINK and
342 .\" EMULTIHOP error conditions; POSIX.1 does not document ELOOP.
343 .\" X/OPEN does not document EFAULT, ENOMEM or EIO.
348 Hard links, as created by
350 cannot span filesystems.
355 POSIX.1-2001 says that
359 if it is a symbolic link.
360 However, since kernel 2.0,
361 .\" more precisely: since kernel 1.3.56
362 Linux does not do so: if
364 is a symbolic link, then
366 is created as a (hard) link to the same symbolic link file
369 becomes a symbolic link to the same file that
372 Some other implementations behave in the same manner as Linux.
373 .\" For example, the default Solaris compilation environment
374 .\" behaves like Linux, and contributors to a March 2005
375 .\" thread in the Austin mailing list reported that some
376 .\" other (System V) implementations did/do the same -- MTK, Apr 05
377 POSIX.1-2008 changes the specification of
379 making it implementation-dependent whether or not
381 is dereferenced if it is a symbolic link.
382 For precise control over the treatment of symbolic links when
386 On older kernels where
388 is unavailable, the glibc wrapper function falls back to the use of
397 are relative pathnames,
398 glibc constructs pathnames based on the symbolic links in
400 that correspond to the
406 On NFS filesystems, the return code may be wrong in case the NFS server
407 performs the link creation and dies before it can say so.
410 to find out if the link got created.
418 .BR path_resolution (7),
421 This page is part of release 3.78 of the Linux
424 A description of the project,
425 information about reporting bugs,
426 and the latest version of this page,
428 \%http://www.kernel.org/doc/man\-pages/.