Readlink
   HOME

TheInfoList



OR:

The command is a standard Unix command utility used to create a
hard link In computing, a hard link is a directory entry (in a directory-based file system) that associates a name with a file. Thus, each file must have at least one hard link. Creating additional hard links for a file makes the contents of that file acc ...
or a symbolic link (symlink) to an existing file or directory. The use of a hard link allows multiple
filenames A filename or file name is a name used to uniquely identify a computer file in a directory structure. Different file systems impose different restrictions on filename lengths. A filename may (depending on the file system) include: * name &ndas ...
to be associated with the same
file File or filing may refer to: Mechanical tools and processes * File (tool), a tool used to ''remove'' fine amounts of material from a workpiece **Filing (metalworking), a material removal process in manufacturing ** Nail file, a tool used to gent ...
since a hard link points to the
inode The inode (index node) is a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. Each inode stores the attributes and disk block locations of the object's data. File-system object attribute ...
of a given file, the data of which is stored on
disk Disk or disc may refer to: * Disk (mathematics), a geometric shape * Disk storage Music * Disc (band), an American experimental music band * ''Disk'' (album), a 1995 EP by Moby Other uses * Disk (functional analysis), a subset of a vector sp ...
. On the other hand, symbolic links are special files that refer to other files by
name A name is a term used for identification by an external observer. They can identify a class or category of things, or a single thing, either uniquely, or within a given context. The entity identified by a name is called its referent. A personal ...
. The command by default creates hard links, and when called with the command line
parameter A parameter (), generally, is any characteristic that can help in defining or classifying a particular system (meaning an event, project, object, situation, etc.). That is, a parameter is an element of a system that is useful, or critical, when ...
creates symbolic links. Most
operating systems An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. Time-sharing operating systems schedule tasks for efficient use of the system and may also inc ...
prevent hard links to directories from being created since such a capability could disrupt the structure of a
file system In computing, file system or filesystem (often abbreviated to fs) is a method and data structure that the operating system uses to control how data is stored and retrieved. Without a file system, data placed in a storage medium would be one larg ...
and interfere with the operation of other utilities. The command can however be used to create symbolic links to non-existent files.


History

ln appeared in Issue 2 of the X/Open Portability Guidelines. The version of bundled in GNU coreutils was written by Mike Parker and David MacKenzie. The command is available as a separate package for
Microsoft Windows Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
as part of the UnxUtils collection of
native Native may refer to: People * Jus soli, citizenship by right of birth * Indigenous peoples, peoples with a set of specific rights based on their historical ties to a particular territory ** Native Americans (disambiguation) In arts and entert ...
Win32 ports of common GNU Unix-like utilities. The command has also been ported to the
IBM i IBM i (the ''i'' standing for ''integrated'') is an operating system developed by IBM for IBM Power Systems. It was originally released in 1988 as OS/400, as the sole operating system of the IBM AS/400 line of systems. It was renamed to i5/OS in ...
operating system.


Links

Links allow more than one filename to refer to the same file as in the case of a
hard link In computing, a hard link is a directory entry (in a directory-based file system) that associates a name with a file. Thus, each file must have at least one hard link. Creating additional hard links for a file makes the contents of that file acc ...
or act as pointers to a filename as in the case of a
soft link In computing, a symbolic link (also symlink or soft link) is a file whose purpose is to point to a file or directory (called the "target") by specifying a Path (computing), path thereto. Symbolic links are supported by POSIX and by most Unix-lik ...
. Both hard links and soft links can be created by the command. Specifically, #
Hard link In computing, a hard link is a directory entry (in a directory-based file system) that associates a name with a file. Thus, each file must have at least one hard link. Creating additional hard links for a file makes the contents of that file acc ...
s, also known simply as links, are objects that associate the filename with the
inode The inode (index node) is a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. Each inode stores the attributes and disk block locations of the object's data. File-system object attribute ...
, and therefore the file contents itself. A given file on disk could have multiple links scattered through the directory hierarchy, with all of the links being equivalent since they all associate with the same
inode The inode (index node) is a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. Each inode stores the attributes and disk block locations of the object's data. File-system object attribute ...
. Creating a link therefore does not copy the contents of the file but merely causes another name to be associated with the same contents. Each time a hard link is created, a link counter that is a part of the inode structure gets incremented; a file is not deleted until its reference count reaches zero. However, hard links can only be created on the same
file system In computing, file system or filesystem (often abbreviated to fs) is a method and data structure that the operating system uses to control how data is stored and retrieved. Without a file system, data placed in a storage medium would be one larg ...
; this can prove to be a disadvantage. # Symbolic links are special files which, when encountered during pathname resolution, modify th
pathname resolution
to be taken to the location which the symbolic link contains. The content of the symbolic link is therefore the destination
path A path is a route for physical travel – see Trail. Path or PATH may also refer to: Physical paths of different types * Bicycle path * Bridle path, used by people on horseback * Course (navigation), the intended path of a vehicle * Desire p ...
string, which can also be examined using the command line utility. The symbolic link may contain an arbitrary string which does not refer to the location of an existing file. Such a symbolic link will fail until a file is created at the location which is contained by the symbolic link. By contrast, a symbolic link to an existing file will fail if the existing file is moved to a different location (or renamed).


Specification

The utility on systems compliant with the Single Unix Specification is specified in the Shell and Utilities (XCU) document, which forms a part of the Single Unix Specification. A mostly identical document is part of
POSIX The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines both the system- and user-level application programming interf ...
. The specification describes two ways of invoking the utility. Specifically, ::In the "single file" invocation the utility creates a new hard link (directory entry) for the source file specified by the ' operand at the destination path specified by the ' operand. However, if the option is specified, a symbolic link is created. :: ln fs -Psource_file target_file ::In the "multiple file" invocation the utility creates a new hard link
directory entry
, or if the option is specified, a symbolic link, for each file specified by the ' operand, at a destination path in an existing directory named by operand '. :: ln fs -Psource_file_1 source_file_2 ... target_dir The specification also specifies the command line options that must be supported: :: Force existing destination pathnames to be removed to allow the link. :: For each ' operand that names a file that is a symbolic link, create a hard link to the file referenced by the symbolic link. :: For each ' operand that names a file that is a symbolic link, create a (hard) link to the symbolic link itself. :: Create symbolic links instead of hard links. If the -s option is specified, the -L and -P options are silently ignored. ::If more than one of the mutually-exclusive options and is specified the last option specified determines the behavior of the utility. ::If the option is not specified and neither a nor a option is specified, the implementation defines which of the and options will be used as the default. If neither target file nor target directory are specified, links will be created in the current working directory.


See also

* List of Unix commands *
NTFS junction point The NTFS file system defines various ways to redirect files and folders, e.g., to make a file point to another file or its contents without making a copy of it. The object being pointed to is called the target. Such file is called a hard or symbo ...


References


External links

* * * * * {{Core Utilities commands Standard Unix programs Unix SUS2008 utilities IBM i Qshell commands