Likewise, the mv command moves or renames the link, not the target. The rm (delete file) command, however, removes the link itself, not the target file. Commands which read or write file contents will access the contents of the target file. Any file system management commands (e.g., cp, rm) may be used on the symbolic link. link_path is the path of the symbolic link.Īfter creating the symbolic link, it may generally be treated as an alias for the target. Usually the target will exist, although symbolic links may be created to non-existent targets. Target_path is the relative or absolute path to which the symbolic link should point. The following command creates a symbolic link at the command-line interface (shell): Symlinks were introduced in 4.2BSD Unix from U.C.
When the ln -s flag is specified, the symlink() system call is used instead, creating a symbolic link. The ln shell command normally uses the link system call, which creates a hard link. In POSIX-compliant operating systems, symbolic links are created with the symlink system call. This offers the opportunity to create a more intuitive or application-specific directory tree and to reorganize the system without having to redesign the core set of system functions and utilities. This is accomplished with several mechanisms, such as variant, context-dependent symbolic links. Some Unix as well as Linux distributions use symbolic links extensively in an effort to reorder the file system hierarchy. Programs that need to handle symbolic links specially (e.g., shells and backup utilities) thus need to identify and manipulate them directly. Some shells heuristically try to uphold the illusion of a tree-shaped hierarchy, but when they do, this causes them to produce different results from other programs that manipulate pathnames without such heuristic, relying on the operating system instead. Even the Unix standard for navigating to a directory's parent directory no longer works reliably in the face of symlinks. However, they have the effect of changing an otherwise hierarchic filesystem from a tree into a directed graph, which can have consequences for such simple operations as determining the current directory of a process.
Symbolic links operate transparently for many operations: programs that read or write to files named by a symbolic link will behave as if operating directly on the target file. Hard links always refer to an existing file, whereas symbolic links may contain an arbitrary path that does not point to anything. Hard links do not link paths on different volumes or file systems, whereas symbolic links may point to any file or directory irrespective of the volumes on which the link and target reside. Symbolic links are different from hard links. Symbolic links pointing to moved or non-existing targets are sometimes called broken, orphaned, dead, or dangling. If a symbolic link points to a target, and sometime later that target is moved, renamed or deleted, the symbolic link is not automatically updated or deleted, but continues to exist and still points to the old target, now a non-existing location or file. If a symbolic link is deleted, its target remains unaffected. The symbolic link is a second file that exists independently of its target. This other file or directory is called the "target".