| Dictionary: ln |
| 5min Related Video: ln |
| Measures and Units: ln |
mathematics Abbreviation for natural logarithm.
| Wikipedia: Ln (Unix) |
|
|
This article's tone or style may not be appropriate for Wikipedia. Specific concerns may be found on the talk page. See Wikipedia's guide to writing better articles for suggestions. (September 2008) |
|
|
This article contains instructions, advice, or how-to content. The purpose of Wikipedia is to present facts, not to train. Please help improve this article either by rewriting the how-to content or by moving it to Wikiversity or Wikibooks. (September 2009) |
ln is a standard Unix command used to create links (link) to files.
Contents |
Links allow more than one file name to refer to the same file, elsewhere.
There are two types of links, both of which are created by ln:
These links behave differently when the source of the link (what is being linked to) is moved or removed. Symbolic links are not updated (they merely contain a string which is the pathname of its target); hard links always refer to the source, even if moved or removed.
The Single Unix Specification (SUS) specifies the behaviour that a link or links (either symbolic or hard) will be created where specified that will link to the target file (or directory) specified.
More precisely, ln can be invoked in one of two ways: two arguments—first an argument specifying the source file then the target, or multiple (greater than two) arguments, specifying firstly a number of source files, then a directory in which all the links are to be created. In the latter invocation, the names of the links will be that of the source file. This invocation will be assumed if the last argument is a directory. If invoked in the latter form, ln's behaviour is not specified (it is implementation-defined).
ln is specified to use behaviour identical to that of the standard unlink() and link() functions.
The SUS mandates for ln two options: -f will force removal of existing files to allow the link to be created; and -s will create symbolic links. Therefore, ln with no options creates a hard link, ln -f forces a hard link, ln -s creates a symbolic link, and ln -fs forces a symbolic link.
Other Unix and Unix-like operating systems may add extra options. GNU ln adds options such as -b to back up files before creating links, -v to print out the name of each file before links are created, and others. BSD ln adds -h, preventing ln from descending into targets whose symlinks point to directories
ln file_name link_name
would have the effect of creating a hard link called link_name that points to the same data as the existing file file_name.
|
|
This article contains instructions, advice, or how-to content. The purpose of Wikipedia is to present facts, not to train. Please help improve this article either by rewriting the how-to content or by moving it to Wikiversity or Wikibooks. (September 2009) |
To begin with, enter the directory called "test":
alex@ubuntu:~/playground/test$ ls -ali total 8 969797 drwxr-xr-x 2 alex alex 4096 Dec 9 09:10 . 1036602 drwxr-xr-x 3 alex alex 4096 Dec 9 09:10 .. alex@ubuntu:~/playground/test$
There is nothing in it. Let's create a small text file called data.txt:
alex@ubuntu:~/playground/test$ echo "some data" > data.txt alex@ubuntu:~/playground/test$ ls -ali total 12 969797 drwxr-xr-x 2 alex alex 4096 Dec 9 09:11 . 1036602 drwxr-xr-x 3 alex alex 4096 Dec 9 09:10 .. 969768 -rw-r--r-- 1 alex alex 10 Dec 9 09:11 data.txt alex@ubuntu:~/playground/test$
Notice that the reference count of the directory (total 8) just increased (total 12). The new file data.txt is stored in inode 969768. Let's create a symbolic (soft) link to data.txt. We will name our symbolic link slink.txt:
alex@ubuntu:~/playground/test$ ln -s data.txt slink.txt alex@ubuntu:~/playground/test$ ls -ali total 12 969797 drwxr-xr-x 2 alex alex 4096 Dec 9 09:11 . 1036602 drwxr-xr-x 3 alex alex 4096 Dec 9 09:10 .. 969768 -rw-r--r-- 1 alex alex 10 Dec 9 09:11 data.txt 969817 lrwxrwxrwx 1 alex alex 8 Dec 9 09:11 slink.txt -> data.txt alex@ubuntu:~/playground/test$
The reference count of the directory has not changed (total 12). Our symbolic (soft) link is stored in a different inode than the text file (969817). The information stored in data.txt is accessible through the slink.txt:
alex@ubuntu:~/playground/test$ file slink.txt slink.txt: symbolic link to `data.txt' alex@ubuntu:~/playground/test$ cat slink.txt some data alex@ubuntu:~/playground/test$
If we delete the text file data.txt, slink.txt becomes a broken link and our data is lost.
alex@ubuntu:~/playground/test$ rm data.txt alex@ubuntu:~/playground/test$ ls -ali total 8 969797 drwxr-xr-x 2 alex alex 4096 Dec 9 09:36 . 1036602 drwxr-xr-x 3 alex alex 4096 Dec 9 09:32 .. 969817 lrwxrwxrwx 1 alex alex 8 Dec 9 09:11 slink.txt -> data.txt alex@ubuntu:~/playground/test$ file slink.txt slink.txt: broken symbolic link to `data.txt' alex@ubuntu:~/playground/test$ cat slink.txt cat: slink.txt: No such file or directory alex@ubuntu:~/playground/test$
If slink.txt was a hard link, our data would still be accessible through slink.txt. Also, if you delete the soft link itself, the data would still be there:
$ ls -ali
63500 drwxr-xr-x 2 sc69876 support 96 Aug 29 18:14 .
43038 drwxr-xr-x 12 sc69876 support 1024 Aug 29 18:13 ..
104690 -rw-r--r-- 1 sc69876 support 10 Aug 29 18:13 data.txt
104825 lrwxrwxrwx 1 sc69876 support 8 Aug 29 18:14 slink.txt -> data.txt
$ rm slink.txt
$ ls -ali
63500 drwxr-xr-x 2 sc69876 support 96 Aug 29 18:15 .
43038 drwxr-xr-x 12 sc69876 support 1024 Aug 29 18:13 ..
104690 -rw-r--r-- 1 sc69876 support 10 Aug 29 18:13 data.txt
|
||||||||||||||||||||||||||
This entry is from Wikipedia, the leading user-contributed encyclopedia. It may not have been reviewed by professional editors (see full disclaimer)
| Best of the Web: ln |
Some good "ln" pages on the web:
Math mathworld.wolfram.com |
| Shopping: ln |
| natural logarithm | |
| Arrhenius equation | |
| prime number theorem (mathematics) |
| What is the number of nigerians ln spain? Read answer... | |
| Who has the bigest head ln the world? Read answer... | |
| What are the spiritual beings ln islam? Read answer... |
| How big is a ln ft? | |
| Why is the symbol for natural log ln? | |
| What role LN has in steel pipe? |
Copyrights:
![]() | Dictionary. The American Heritage® Dictionary of the English Language, Fourth Edition Copyright © 2007, 2000 by Houghton Mifflin Company. Updated in 2009. Published by Houghton Mifflin Company. All rights reserved. Read more | |
![]() | Measures and Units. A Dictionary of Weights, Measures, and Units. Copyright © Donald Fenna 2002, 2004. All rights reserved. Read more | |
![]() | Wikipedia. This article is licensed under the Creative Commons Attribution/Share-Alike License. It uses material from the Wikipedia article "Ln (Unix)". Read more |
Mentioned in