Symbolic Link - POSIX and Unix-like Operating Systems

POSIX and Unix-like Operating Systems

In POSIX-compliant operating systems, symbolic links are created with the symlink system call. The ln shell command normally uses the link system call, which creates a hard link. When the ln -s flag is specified, the symlink system call is used instead, creating a symbolic link.

The following command creates a symbolic link at the command-line interface (shell):

ln -s target_path link_path

target_path is the relative or absolute path to which the symbolic link should point. Usually the target will exist, although symbolic links may be created to non-existent targets. link_path is the path of the symbolic link.

After creating the symbolic link, it may generally be treated as an alias for the target. Any file system management commands (e.g., cp, rm) may be used on the symbolic link. Commands which read or write file contents will access the contents of the target file. The rm (delete file) command, however, removes the link itself, not the target file.

The POSIX directory listing application, ls, denotes symbolic links with an arrow after the name, pointing to the name of the target file (see following example), when the long directory list is requested (-l option). When a directory listing of a symbolic link that points to a directory is requested, only the link itself will be displayed. In order to obtain a listing of the linked directory, the path must include a trailing directory separator character ('/', slash).

$ mkdir -p /tmp/one/two $ echo "test_a" >/tmp/one/two/a $ echo "test_b" >/tmp/one/two/b $ cd /tmp/one/two $ ls -l -rw-r--r-- 1 user group 7 Jan 01 10:01 a -rw-r--r-- 1 user group 7 Jan 01 10:01 b $ cd /tmp $ ln -s /tmp/one/two three $ ls -l /tmp/three lrwxrwxrwx 1 user group 12 Jul 22 10:02 /tmp/three -> /tmp/one/two $ ls -l /tmp/three/ -rw-r--r-- 1 user group 7 Jan 01 10:01 a -rw-r--r-- 1 user group 7 Jan 01 10:01 b $ cd three $ ls -l -rw-r--r-- 1 user group 7 Jan 01 10:01 a -rw-r--r-- 1 user group 7 Jan 01 10:01 b $ cat a test_a $ cat /tmp/one/two/a test_a $ echo "test_c" >/tmp/one/two/a $ cat /tmp/one/two/a test_c $ cat /tmp/three/a test_c

Read more about this topic:  Symbolic Link

Famous quotes containing the words operating and/or systems:

    Many people operate under the assumption that since parenting is a natural adult function, we should instinctively know how to do it—and do it well. The truth is, effective parenting requires study and practice like any other skilled profession. Who would even consider turning an untrained surgeon loose in an operating room? Yet we “operate” on our children every day.
    Louise Hart (20th century)

    We have done scant justice to the reasonableness of cannibalism. There are in fact so many and such excellent motives possible to it that mankind has never been able to fit all of them into one universal scheme, and has accordingly contrived various diverse and contradictory systems the better to display its virtues.
    Ruth Benedict (1887–1948)