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(2).)
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  filesystem  containing oldpath and newpath does not support
63              the creation of hard links.
64
65       EROFS  The file is on a read-only filesystem.
66
67       EXDEV  oldpath and newpath are not  on  the  same  mounted  filesystem.
68              (Linux  permits  a  filesystem to be mounted at multiple points,
69              but link(2) does not work across different mount points, even if
70              the same filesystem is mounted on both.)
71

NOTES

73       Hard  links,  as  created  by link(), cannot span filesystems. Use sym‐
74       link() if this is required.
75
76       POSIX.1-2001 says that link() should dereference oldpath  if  it  is  a
77       symbolic link.  However, Linux does not do so: if oldpath is a symbolic
78       link, then newpath is created as a (hard) link  to  the  same  symbolic
79       link  file (i.e., newpath becomes a symbolic link to the same file that
80       oldpath refers to).  Some other implementations behave in the same man‐
81       ner as Linux.
82

CONFORMING TO

84       SVr4, 4.3BSD, POSIX.1-2001 (except as noted above).
85

BUGS

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

SEE ALSO

92       ln(1), linkat(2), open(2), path_resolution(2), rename(2), stat(2), sym‐
93       link(2), unlink(2)
94
95
96
97Linux 2.6.7                       2004-06-23                           LINK(2)
Impressum