Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Ln (Unix)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Shell command for creating a link file}} {{Lowercase title}} {{Infobox software | name = ln | logo = | screenshot = Ln-example-command.gif | screenshot size = | caption = Example usage of {{code|ln}} utility | author = [[AT&T Bell Laboratories]] | developer = Various [[open-source software|open-source]] and [[commercial software|commercial]] developers | released = {{Start date and age|1971|11|3}} | latest release version = | latest release date = | operating system = [[Unix]], [[Unix-like]], [[IBM i]] | platform = [[Cross-platform]] | genre = [[Command (computing)|Command]] | license = [[coreutils]]: [[GPLv3+]] | website = }} '''{{code|ln}}''' is a [[shell (computing)|shell]] [[command (computing)|command]] for creating a link file to an existing [[computer file|file]] or [[computer directory|directory]].<ref name=UNIXKP>{{cite book|last1=Kernighan|first1=Brian W.|last2=Pike|first2=Rob|title=The Unix programming environment.|date=1984|publisher=Prentice-Hall|location=Englewood Cliffs, N.J.|isbn=013937681X|page=[https://archive.org/details/unixprogramminge0000kern/page/59 59]|url-access=registration|url=https://archive.org/details/unixprogramminge0000kern/page/59}}</ref> By default, the command creates a [[hard link]], but with the {{code|-s}} [[Command-line interface|command line]] option, it creates a [[symbolic link]].<ref>{{cite web|title=ln - The Open Group Base Specifications Issue 7|url=http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ln.html|website=pubs.opengroup.org|publisher=The IEEE and The Open Group|access-date=7 August 2015}}</ref> 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.<ref>{{cite web|title=Why are hard links not allowed to directories in UNIX/Linux?|url=http://unix.stackexchange.com/questions/22394/why-hard-links-not-allowed-to-directories-in-unix-linux?rq=1|website=unix.stackexchange.com|access-date=7 August 2015}}</ref> The command can create a symbolic link to non-existent file.<ref name=GNULnman /> The command appeared in Issue 2 of the [[X/Open]] Portability Guidelines.<ref name=SUS/> The version in [[GNU Core Utilities]] was written by Mike Parker and David MacKenzie.<ref>{{man|1|ln|ManKier}}</ref> The command is available in [[Windows]] via [[UnxUtils]]<ref>{{Cite web|url=http://unxutils.sourceforge.net/|title=Native Win32 ports of some GNU utilities|website=unxutils.sourceforge.net}}</ref> and has been ported to [[IBM i]].<ref>{{cite web |title=IBM System i Version 7.2 Programming Qshell |language=en |author=IBM |website=[[IBM]] |author-link=IBM |url=https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc |access-date=2020-09-05 }}</ref> ==Links== A link allows more than one [[file path|path]] to refer to the same file. A hard link is a directory entry that refers to a file's [[inode]] (an internal [[Reference (computer science)|reference]]). A file can have multiple hard links {{endash}} each referring to the same [[inode]].<ref name=libc /> 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 [[Reference counting#File systems|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.<ref name=UNIXKP /><ref name=IBMInode>{{cite web|title=Speaking UNIX: It is all about the inode|url=http://www.ibm.com/developerworks/aix/library/au-speakingunix14/|website=ibm.com|publisher=IBM developerWorks|access-date=7 August 2015}}</ref> A hard link can only refer to an object on the same [[file system]].<ref>{{cite book|last1=Bovet|first1=Daniel P.|last2=Cesati|first2=Marco|title=Understanding the Linux Kernel|date=2005|publisher=Safari Tech Books Online|location=Boston, MA|isbn=0596005652|page=14|edition=3rd}}</ref> A symbolic link refers to another file by its path (a symbolic reference).<ref name=GNULnman>{{cite web|title=GNU Coreutils: ln invocation|url=https://www.gnu.org/software/coreutils/manual/html_node/ln-invocation.html|website=gnu.org|publisher=Free Software Foundation, Inc.|access-date=7 August 2015}}</ref> When encountered during pathname resolution, modify the [http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13 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 {{code|readlink}} command.<ref>{{cite web|title=readlink(1) - Linux man page|url=http://linux.die.net/man/1/readlink|website=linux.die.net|access-date=7 August 2015|ref=ReadlinkMan}}</ref> 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.<ref name=libc>{{cite book|last1=Loosemore|first1=Sandra|last2=Stallman|first2=Richard M.|last3=McGrath|first3=Roland|last4=Oram|first4=Andrew|last5=Drepper|first5=Ulrich|title=The GNU C Library Reference Manual|publisher=Free Software Foundation, Inc|page=392|url=https://www.gnu.org/software/libc/manual/pdf/libc.pdf|access-date=7 August 2015}}</ref> ==Use == Per the [[Single Unix Specification]], the {{code|ln}} command is specified in the Shell and Utilities (XCU) document.<ref name=SUSOverview>{{cite web|title=The Single UNIX Specification, Version 4 - Overview|url=http://www.unix.org/version4/overview.html|website=unix.org|publisher=unix.org|access-date=7 August 2015}}</ref> [[POSIX]] includes a similar specification.<ref name=SUS>{{man|1|ln|SUS}}</ref> If neither target file nor target directory are specified, links are created in the current [[working directory]]. ===Options=== The specification indicates command line options that must be supported: * {{code|-f}} (force) [[clobbering|Clobbers]] an existing file if the output path specifies an existing file * {{code|-L}} If a source operand specifies a symbolic link, create a hard link to the link's target file * {{code|-P}} If a source operand specifies a symbolic link, create a hard link to the symbolic link file * {{code|-s}} Create symbolic links instead of hard links; causes {{code|-L}} and {{code|-P}} to be silently ignored If more than one of the mutually-exclusive options {{code|-L}} and {{code|-P}} is specified, the last option specified determines the resulting behavior. If the {{code|-s}} option is not specified and neither a {{code|-L}} nor a {{code|-P}} option is specified, the implementation defines which of the {{code|-L}} and {{code|-P}} options is used by default. ===Single file invocation=== The command creates a new link to the path indicated by {{code|source}}; stored at the path indicated by {{code|target}}. The syntax is as follows: <syntaxhighlight lang="terminal"> ln [-fs] [-L|-P] source target </syntaxhighlight> ===Multiple file invocation=== The command creates a new link to each file specified by the {{code|source_#}} operands; stored in an existing directory indicated by {{code|target_dir}}. <syntaxhighlight lang="terminal"> ln [-fs] [-L|-P] source_1 source_2 ... target_dir </syntaxhighlight> ==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== {{Reflist|30em}} ==External links== {{Wikibooks|Guide to Unix|Commands/File_System_Utilities#ln| File System Utilities - ln}} * {{man|1|ln|die.net}} * {{man|1|ln|FreeBSD}} * {{man|1|ln|NetBSD}} * {{man|1|ln|OpenBSD}} * {{man|1|ln|Darwin}} {{Unix commands}} {{Core Utilities commands}} [[Category:Standard Unix programs]] [[Category:Unix SUS2008 utilities]] [[Category:IBM i Qshell commands]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite book
(
edit
)
Template:Cite web
(
edit
)
Template:Code
(
edit
)
Template:Core Utilities commands
(
edit
)
Template:Endash
(
edit
)
Template:Infobox
(
edit
)
Template:Infobox software
(
edit
)
Template:Lowercase title
(
edit
)
Template:Main other
(
edit
)
Template:Man
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Sister project
(
edit
)
Template:Template other
(
edit
)
Template:Unix commands
(
edit
)
Template:Wikibooks
(
edit
)