ln [ -s ] [ -f ] sourcefile ... targetdirectory
By default ln makes hard links. A hard link to a file is indistinguishable from the original directory entry; any changes to a file are effective independent of the name used to reference the file. Hard links may not span filesystems and may not refer to directories.
The -s option causes ln to create symbolic links. A symbolic link contains the name of the file to which it is linked; this file does not need to exist prior to the symbolic link. Symbolic links may span file systems and may refer to directories.
When ln is given two arguments, and the second argument does not exist, ln creates a directory entry called targetfile that is a link to sourcefile.
If the last argument is the name of a directory, ln creates a new entry in the directory for each sourcefile given. The name of each new entry will be the basename of the corresponding sourcefile.
If the -f option is not specified and the target filename already exists, the link is not created. If the -f option is specified, the existing file is unlinked before the new link is created.
If you try to create a symbolic link to a file in your current
working directory using a relative pathname, you will not achieve
the desired result. In this example
ln -s sln /tmp/sln
you are creating a file /tmp/sln that refers to a file sln in the /tmp directory: that is, you are creating a self-referential file in /tmp rather than a reference to the file sln in the current working directory.
A listing of the file /tmp/sln produces the following output:
lrwxrwxrwx 1 user1 group1 2 Sep 07 10:35 /tmp/sln -> slnIf you then try to open the file using a command such as vi, an error will be returned because the symbolic link ends up ``chasing its own tail''. You cannot avoid this situation by entering the command:
rather, you should use the full pathname:
ln -s /user1/sln /tmp/sln
A listing of /tmp/sln will then produce this output:
lrwxrwxrwx 1 user1 group1 2 Sep 07 10:35 /tmp/sln -> /user1/slnThe symbolic link correctly references the file in the current working directory.
Cannot make symbolic link.
ISO/IEC DIS 99452:1992, Information technology Portable Operating System Interface (POSIX) Part 2: Shell and Utilities (IEEE Std 1003.21992);
AT&T SVID Issue 2;
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992.