Information about Ln (unix)

ln is a standard Unix program used to create links (link) to files.

Link files

Links allow more than one file to refer to the same file, elsewhere.

There are two types of links, both of which are created by ln:
  • symbolic links, which refer to a symbolic path indicating the abstract location of another file, and
  • hard links, which refer to the specific location of physical data.
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.

Specification

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.

Usage

The SUS mandates for ln two options: -f, which will force removal of existing files to allow the link to be created, and -s, to specify symbolic links.

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 names of each files before links are created, and others. BSD ln adds -h, preventing ln from descending into targets whose symlinks point to directories

ln xyz abc

would have the effect of creating a hard link called abc that points to the same data as the existing file xyz.

Symbolic link creation and deletion:

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

You should use unlink command to do this:

$ ls -ali

63500 drwxr-xr-x 2 sc6945 support 96 Aug 29 18:20 . 43038 drwxr-xr-x 12 sc6945 support 1024 Aug 29 18:13 .. 104690 -rw-r--r-- 1 sc6945 support 10 Aug 29 18:13 data.txt 104825 lrwxrwxrwx 1 sc6945 support 8 Aug 29 18:20 slink.txt -> data.txt $ unlink slink.txt

$ ls -ali

63500 drwxr-xr-x 2 sc6945 support 96 Aug 29 18:20 . 43038 drwxr-xr-x 12 sc6945 support 1024 Aug 29 18:13 .. 104690 -rw-r--r-- 1 sc6945 support 10 Aug 29 18:13 data.txt

See also

External links

  • ln -- specification from the Single Unix Specification

Manual pages



Unix (officially trademarked as UNIX®) is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs including Ken Thompson, Dennis Ritchie and Douglas McIlroy.
..... Click the link for more information.
symbolic link (often shortened to symlink and also known as a soft link) consists of a special type of file that serves as a reference to another file or directory. Unix-like operating systems in particular often feature symbolic links.
..... Click the link for more information.
In computing, a hard link is a reference, or pointer, to physical data on a storage volume. On most file systems, all named files are hard links. The name associated with the file is simply a label that refers the operating system to the actual data.
..... Click the link for more information.
The Single UNIX Specification (SUS) is the collective name of a family of standards for computer operating systems to qualify for the name "Unix". The SUS is developed and maintained by the Austin Group, based on earlier work by the IEEE and The Open Group.
..... Click the link for more information.
Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification.
..... Click the link for more information.
In computer science, reference counting is a technique of storing the number of references, pointers, or handles to a resource such as an object or block of memory. It is typically used as a means of deallocating objects which are no longer referenced.
..... Click the link for more information.
In computing, an inode is a data structure on a traditional Unix-style file system such as UFS. An inode stores basic information about a regular file, directory, or other file system object.
..... Click the link for more information.
Broken link may refer to:
  • "Broken Link" (DS9 episode), the final fourth-season episode of Star Trek: Deep Space Nine
  • Dead link, link on the world wide web that points to a webpage or server that is permanently unavailable

..... Click the link for more information.
In computing, a hard link is a reference, or pointer, to physical data on a storage volume. On most file systems, all named files are hard links. The name associated with the file is simply a label that refers the operating system to the actual data.
..... Click the link for more information.
NTFS junction point (JP) is a feature of the NTFS file system version 3.0 or later. It is a type of NTFS reparse point. Junction Points can be used in a similar way to symbolic links — allowing the creation of a link to a folder that is, for most intents and purposes, the
..... Click the link for more information.
Printing: lp Communications: inetd netstat ping rlogin nc traceroute Searching: find grep strings Miscellaneous: banner bc cal dd man size yes
..... Click the link for more information.
GNU (pronounced ) is a computer operating system composed entirely of free software.
..... Click the link for more information.
GNU Core Utilities or coreutils is a package of GNU software containing many of the basic tools such as cat, ls, and rm needed for Unix-like operating systems. It is a combination of a number of earlier packages, including textutils, shellutils, and
..... Click the link for more information.
OpenBSD is a Unix-like computer operating system descended from Berkeley Software Distribution (BSD), a Unix derivative developed at the University of California, Berkeley. It was forked from NetBSD by project leader Theo de Raadt in late 1995.
..... Click the link for more information.
Unix (officially trademarked as UNIX®) is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs including Ken Thompson, Dennis Ritchie and Douglas McIlroy.
..... Click the link for more information.
command line interface or CLI is a method of interacting with an operating system or software using a command line interpreter. This command line interpreter may be a text terminal, terminal emulator, or remote shell client such as PuTTY.
..... Click the link for more information.
Printing: lp Communications: inetd netstat ping rlogin nc traceroute Searching: find grep strings Miscellaneous: banner bc cal dd man size yes
..... Click the link for more information.
The cat command is a standard Unix program used to concatenate and display files. The name is from , a synonym of concatenate.

Specification

The Single Unix Specification specifies the behavior that each of the files given in sequence as arguments will write their
..... Click the link for more information.
chattr is a UNIX program that allows a user to set certain attributes to a file. Mostly chattr is used to make files immutable so that password files and certain system files cannot be erased during software upgrades.
..... Click the link for more information.
cd, sometimes also available as chdir (change directory), is a command line command to change the current working directory in operating systems such as Unix, Windows and DOS.
..... Click the link for more information.
The chmod command (abbreviated from change mode) is a shell command in Unix and Unix-like environments.

When executed, the command can change file system modes of files and directories. The modes include permissions and special modes.
..... Click the link for more information.
The chown command is used on Unix-like systems to change the owner of a file. In most implementations, it can only be executed by the Superuser. Unprivileged (regular) users who wish to change the group of a file that they own may use chgrp.
..... Click the link for more information.
The chgrp command is used by unprivileged users on Unix-like systems to change the group associated with a file. Unlike the chown command, chgrp allows regular users to change groups, but only to one of which they are a member.
..... Click the link for more information.
cksum is a POSIX command that reads the files specified by the File parameter and calculates a checksum, cyclic redundancy check (CRC) and the byte count for a file or files. If no files are specified, the cksum command reads standard input.
..... Click the link for more information.
cmp is a command line utility for computer systems that use a Unix operating system. It compares two files of any type and writes the results to the standard output. By default, cmp is silent if the files are the same; if they differ, the byte and line number at which the first
..... Click the link for more information.

..... Click the link for more information.
du (abbreviated from disk usage) is a standard Unix program used to estimate the file space usage; space used under a particular directory or files on a file system.

History

The du utility first appeared in version 1 of AT&T UNIX.
..... Click the link for more information.
df (abbreviated from disk free) is a standard Unix computer program used to display the amount of available disk space for filesystems on which the invoking user has appropriate read access, df
..... Click the link for more information.
file is a standard Unix program for determining the type of data contained in a file.

History

The original version of file originated in Unix Research Version 4 in 1973.
..... Click the link for more information.
fuser is a UNIX command showing which processes are using a specified file.


..... Click the link for more information.


This article is copied from an article on Wikipedia.org - the free encyclopedia created and edited by online user community. The text was not checked or edited by anyone on our staff. Although the vast majority of the wikipedia encyclopedia articles provide accurate and timely information please do not assume the accuracy of any particular article. This article is distributed under the terms of GNU Free Documentation License.
Herod_Archelaus


page counter