1.\" Copyright (c) 1983, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. Neither the name of the University nor the names of its contributors 13.\" may be used to endorse or promote products derived from this software 14.\" without specific prior written permission. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.Dd April 15, 2025 29.Dt SYMLINK 2 30.Os 31.Sh NAME 32.Nm symlink , 33.Nm symlinkat 34.Nd make symbolic link to a file 35.Sh LIBRARY 36.Lb libc 37.Sh SYNOPSIS 38.In unistd.h 39.Ft int 40.Fn symlink "const char *name1" "const char *name2" 41.Ft int 42.Fn symlinkat "const char *name1" "int fd" "const char *name2" 43.Sh DESCRIPTION 44A symbolic link 45.Fa name2 46is created to 47.Fa name1 48.Fa ( name2 49is the name of the 50file created, 51.Fa name1 52is the string 53used in creating the symbolic link). 54Either name may be an arbitrary path name; the files need not 55be on the same file system. 56.Pp 57The 58.Fn symlinkat 59system call is equivalent to 60.Fn symlink 61except in the case where 62.Fa name2 63specifies a relative path. 64In this case the symbolic link is created relative to the directory 65associated with the file descriptor 66.Fa fd 67instead of the current working directory. 68If 69.Fn symlinkat 70is passed the special value 71.Dv AT_FDCWD 72in the 73.Fa fd 74parameter, the current working directory is used and the behavior is 75identical to a call to 76.Fn symlink . 77.Sh RETURN VALUES 78.Rv -std symlink 79.Sh ERRORS 80The symbolic link succeeds unless: 81.Bl -tag -width Er 82.It Bq Er ENOTDIR 83A component of the 84.Fa name2 85path prefix is not a directory. 86.It Bq Er ENAMETOOLONG 87A component of the 88.Fa name2 89pathname exceeded 255 characters, 90or the entire length of either path name exceeded 1023 characters. 91.It Bq Er ENOENT 92A component of the 93.Fa name2 94path prefix does not exist. 95.It Bq Er EOPNOTSUPP 96The file system containing the file named by 97.Fa name2 98does not support symbolic links. 99.It Bq Er EACCES 100A component of the 101.Fa name2 102path prefix denies search permission, or write permission is denied on the 103parent directory of the file to be created. 104.It Bq Er ELOOP 105Too many symbolic links were encountered in translating the 106.Fa name2 107path name. 108.It Bq Er EEXIST 109The path name pointed at by the 110.Fa name2 111argument 112already exists. 113.It Bq Er EPERM 114The parent directory of the file named by 115.Fa name2 116has its immutable flag set, see the 117.Xr chflags 2 118manual page for more information. 119.It Bq Er EIO 120An I/O error occurred while making the directory entry for 121.Fa name2 , 122allocating the inode for 123.Fa name2 , 124or writing out the link contents of 125.Fa name2 . 126.It Bq Er EROFS 127The file 128.Fa name2 129would reside on a read-only file system. 130.It Bq Er ENOSPC 131The directory in which the entry for the new symbolic link is being placed 132cannot be extended because there is no space left on the file 133system containing the directory. 134.It Bq Er ENOSPC 135The new symbolic link cannot be created because 136there is no space left on the file 137system that will contain the symbolic link. 138.It Bq Er ENOSPC 139There are no free inodes on the file system on which the 140symbolic link is being created. 141.It Bq Er EDQUOT 142The directory in which the entry for the new symbolic link 143is being placed cannot be extended because the 144user's quota of disk blocks on the file system 145containing the directory has been exhausted. 146.It Bq Er EDQUOT 147The new symbolic link cannot be created because the user's 148quota of disk blocks on the file system that will 149contain the symbolic link has been exhausted. 150.It Bq Er EDQUOT 151The user's quota of inodes on the file system on 152which the symbolic link is being created has been exhausted. 153.It Bq Er EINTEGRITY 154Corrupted data was detected while reading from the file system. 155.It Bq Er EFAULT 156The 157.Fa name1 158or 159.Fa name2 160argument 161points outside the process's allocated address space. 162.El 163.Pp 164In addition to the errors returned by the 165.Fn symlink , 166the 167.Fn symlinkat 168may fail if: 169.Bl -tag -width Er 170.It Bq Er EBADF 171The 172.Fa name2 173argument does not specify an absolute path and the 174.Fa fd 175argument is neither 176.Dv AT_FDCWD 177nor a valid file descriptor open for searching. 178.It Bq Er ENOTDIR 179The 180.Fa name2 181argument is not an absolute path and 182.Fa fd 183is neither 184.Dv AT_FDCWD 185nor a file descriptor associated with a directory. 186.El 187.Sh SEE ALSO 188.Xr ln 1 , 189.Xr chflags 2 , 190.Xr link 2 , 191.Xr lstat 2 , 192.Xr readlink 2 , 193.Xr unlink 2 , 194.Xr symlink 7 195.Sh STANDARDS 196The 197.Fn symlinkat 198system call follows The Open Group Extended API Set 2 specification. 199.Sh HISTORY 200The 201.Fn symlink 202system call appeared in 203.Bx 4.2 . 204The 205.Fn symlinkat 206system call appeared in 207.Fx 8.0 . 208