1LINK(2)                    Linux Programmer's Manual                   LINK(2)
2
3
4

NAME

6       link - make a new name for a file
7

SYNOPSIS

9       #include <unistd.h>
10
11       int link(const char *oldpath, const char *newpath);
12

DESCRIPTION

14       link()  creates  a  new link (also known as a hard link) to an existing
15       file.
16
17       If newpath exists it will not be overwritten.
18
19       This new name may be used exactly as the old  one  for  any  operation;
20       both names refer to the same file (and so have the same permissions and
21       ownership) and it is impossible to tell which name was the "original".
22

RETURN VALUE

24       On success, zero is returned.  On error, -1 is returned, and  errno  is
25       set appropriately.
26

ERRORS

28       EACCES Write  access  to the directory containing newpath is denied, or
29              search permission is denied for one of the  directories  in  the
30              path  prefix  of  oldpath  or  newpath.   (See also path_resolu‐
31              tion(7).)
32
33       EEXIST newpath already exists.
34
35       EFAULT oldpath or newpath points outside your accessible address space.
36
37       EIO    An I/O error occurred.
38
39       ELOOP  Too many symbolic links were encountered in resolving oldpath or
40              newpath.
41
42       EMLINK The  file  referred to by oldpath already has the maximum number
43              of links to it.
44
45       ENAMETOOLONG
46              oldpath or newpath was too long.
47
48       ENOENT A directory component in oldpath or newpath does not exist or is
49              a dangling symbolic link.
50
51       ENOMEM Insufficient kernel memory was available.
52
53       ENOSPC The device containing the file has no room for the new directory
54              entry.
55
56       ENOTDIR
57              A component used as a directory in oldpath or newpath is not, in
58              fact, a directory.
59
60       EPERM  oldpath is a directory.
61
62       EPERM  The  file system containing oldpath and newpath does not support
63              the creation of hard links.
64
65       EROFS  The file is on a read-only file system.
66
67       EXDEV  oldpath and newpath are not on the  same  mounted  file  system.
68              (Linux  permits  a file system to be mounted at multiple points,
69              but link() does not work across different mount points, even  if
70              the same file system is mounted on both.)
71

CONFORMING TO

73       SVr4, 4.3BSD, POSIX.1-2001 (but see NOTES).
74

NOTES

76       Hard  links,  as created by link(), cannot span file systems.  Use sym‐
77       link(2) if this is required.
78
79       POSIX.1-2001 says that link() should dereference oldpath  if  it  is  a
80       symbolic  link.   However,  since  kernel 2.0, Linux does not do so: if
81       oldpath is a symbolic link, then newpath is created as a (hard) link to
82       the  same  symbolic link file (i.e., newpath becomes a symbolic link to
83       the same file that oldpath  refers  to).   Some  other  implementations
84       behave  in the same manner as Linux.  POSIX.1-2008 changes the specifi‐
85       cation of link(), making it  implementation-dependent  whether  or  not
86       oldpath  is dereferenced if it is a symbolic link.  For precise control
87       over the  treatment  of  symbolic  links  when  creating  a  link,  see
88       linkat(2).
89

BUGS

91       On  NFS  file  systems,  the  return  code may be wrong in case the NFS
92       server performs the link creation and dies before it can say  so.   Use
93       stat(2) to find out if the link got created.
94

SEE ALSO

96       ln(1),  linkat(2),  open(2), rename(2), stat(2), symlink(2), unlink(2),
97       path_resolution(7), symlink(7)
98

COLOPHON

100       This page is part of release 3.22 of the Linux  man-pages  project.   A
101       description  of  the project, and information about reporting bugs, can
102       be found at http://www.kernel.org/doc/man-pages/.
103
104
105
106Linux                             2008-08-21                           LINK(2)
Impressum