is a
shell
Shell may refer to:
Architecture and design
* Shell (structure), a thin structure
** Concrete shell, a thin shell of concrete, usually with no interior columns or exterior buttresses
Science Biology
* Seashell, a hard outer layer of a marine ani ...
command
Command may refer to:
Computing
* Command (computing), a statement in a computer language
* command (Unix), a Unix command
* COMMAND.COM, the default operating system shell and command-line interpreter for DOS
* Command key, a modifier key on A ...
for creating a link file to an existing
file or
directory.
By default, the command creates a
hard link
In computing, a hard link is a directory entry (in a Directory (computing), directory-based file system) that associates a name with a Computer file, file. Thus, each file must have at least one hard link. Creating additional hard links for a fil ...
, but with the
command line
A command-line interface (CLI) is a means of interacting with software via command (computing), commands each formatted as a line of text. Command-line interfaces emerged in the mid-1960s, on computer terminals, as an interactive and more user ...
option, it creates a
symbolic 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 thereto.
Symbolic links are supported by POSIX and by most Unix-like operating syste ...
. Most systems disallow a hard link to a directory since such links could disrupt the structure of a
file system and interfere with the operation of other utilities. The command can create a symbolic link to non-existent file.
The command appeared in Issue 2 of the
X/Open X/Open group (also known as the Open Group for Unix Systems and incorporated in 1987 as X/Open Company, Ltd.) was a consortium founded by several European UNIX systems manufacturers in 1984 to identify and promote open standards in the field of info ...
Portability Guidelines.
[ The version in ]GNU Core Utilities
The GNU Core Utilities or coreutils is a collection of GNU software that implements many standard, Unix-based shell commands. The utilities generally provide POSIX compliant interface when the environment variable is set, but otherwise offers ...
was written by Mike Parker and David MacKenzie.
The command is available in Windows
Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
via UnxUtils
UnxUtils is a collection of utility programs that provide popular Unix-based shell commands ported from GNU implementations as native Windows programs that depend only on Win32 and the Microsoft C- runtime ( msvcrt.dll). The collection wa ...
and has been ported to 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 2 ...
.
Links
A link allows more than one 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
* Desir ...
to refer to the same file.
A hard link is a directory entry that refers to a file's inode
An 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 attribu ...
(an internal reference
A reference is a relationship between objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. It is called a ''nam ...
). A file can have multiple hard links each referring to the same inode
An 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 attribu ...
. Creating a hard link does not copy the contents of the file; but merely causes another name to be associated with the same content. When a hard link is created for a file, a counter in its inode is incremented, and removing a hard link results in decrementing the counter. A file is not deleted (to allow reusing its storage space) until its reference count reaches zero. A hard link can only refer to an object on the same file system.
A symbolic link refers to another file by its path (a symbolic reference). When encountered during pathname resolution, modify th
pathname resolution
to be taken to the location which the symbolic link contains. The content of a symbolic link is the target path, which can also be examined via the command. A symbolic link may specify a path that does not refer to an existing file. Resolving such a symbolic link will fail until a file is created at its specified path. Also, a symbolic link to an existing file will fail to resolve if the file is moved.
Use
Per the Single Unix Specification
The Single UNIX Specification (SUS) is a standard for computer operating systems, compliance with which is required to qualify for using the "UNIX" trademark. The standard specifies programming interfaces for the C language, a command-line shell, ...
, the command is specified in the Shell and Utilities (XCU) document. 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 application programming interfaces (APIs), along with comm ...
includes a similar specification.
If neither target file nor target directory are specified, links are created in the current working directory
In computing, the working directory of a process is a directory of a hierarchical file system, if any, dynamically associated with the process. It is sometimes called the current working directory (CWD), e.g. the BSD getcwd function, or just c ...
.
Options
The specification indicates command line options that must be supported:
* (force) Clobbers an existing file if the output path specifies an existing file
* If a source operand specifies a symbolic link, create a hard link to the link's target file
* If a source operand specifies a symbolic link, create a hard link to the symbolic link file
* Create symbolic links instead of hard links; causes and to be silently ignored
If more than one of the mutually-exclusive options and is specified, the last option specified determines the resulting behavior.
If the option is not specified and neither a nor a option is specified, the implementation defines which of the and options is used by default.
Single file invocation
The command creates a new link to the path indicated by ; stored at the path indicated by . The syntax is as follows:
ln fs -Psource target
Multiple file invocation
The command creates a new link to each file specified by the operands; stored in an existing directory indicated by .
ln fs -Psource_1 source_2 ... target_dir
Examples
The following creates a hard link to file foo called bar.
ln foo bar
The following creates a symbolic link to file foo called bar.
ln -s foo bar
See also
* List of POSIX commands
* NTFS junction point
References
External links
*
*
*
*
*
{{Core Utilities commands
Standard Unix programs
Unix SUS2008 utilities
IBM i Qshell commands