fortypoundhead.com

LN

Posted On 2007-05-01 by FortyPoundHead
Keywords:
Tags: Linux Commandline Linux
Views: 1565


Make links between files, by default, it makes hard links; with the '-s' option, it makes symbolic (or "soft") links.

Syntax

ln [Options]... target [Linkname]

ln [Options]... target... Directory

Options

-b
--backup

Make a backup of each file that would otherwise be overwritten or removed. *Note Backup options:

-d
-F
--directory

Allow the super-user to make hard links to directories.

-f
--force

Remove existing destination files.

-i
--interactive

Prompt whether to remove existing destination files.

-n
--no-dereference

When given an explicit destination that is a symlink to a directory, treat that destination as if it were a normal file.

When the destination is an actual directory (not a symlink to one), there is no ambiguity. The link is created in that directory. But when the specified destination is a symlink to a directory, there are two ways to treat the user's request. 'ln' can treat the destination just as it would a normal directory and create the link in it. On the other hand, the destination can be viewed as a non-directory--as the symlink itself. In that case, 'ln' must delete or backup that symlink before creating the new link. The default is to treat a destination that is a symlink to a directory just like a directory.

-s
--symbolic

Make symbolic links instead of hard links. This option merely produces an error message on systems that do not support symbolic links.

-S SUFFIX
--suffix=SUFFIX

Append SUFFIX to each backup file made with '-b'. *Note Backup options:

-v
--verbose

Print the name of each file before linking it.

-V METHOD
--version-control=METHOD

Change the type of backups made with '-b'. The METHOD argument can be 'numbered' (or 't'), 'existing' (or 'nil'), or 'never' (or 'simple').

Description

  • If the last argument names an existing directory, 'ln' creates a link to each TARGET file in that directory, using the TARGETs' names. (But see the description of the '--no-dereference' option below.)
  • If two filenames are given, 'ln' creates a link from the second to the first.
  • If one TARGET is given, 'ln' creates a link to that file in the current directory.
  • It is an error if the last argument is not a directory and more than two files are given. Without '-f' or '-i' (see below), 'ln' will not remove an existing file. Use the '--backup' option to make 'ln' rename existing files.

A "hard link" is another name for an existing file; the link and the original are indistinguishable. Technically speaking, they share the same inode, and the inode contains all the information about a file--indeed, it is not incorrect to say that the inode _is_ the file.

On all existing implementations, you cannot make a hard link to a directory, and hard links cannot cross filesystem boundaries. (These restrictions are not mandated by POSIX, however.)

"Symbolic links" ("symlinks" for short), on the other hand, are a special file type (which not all kernels support: System V release 3 (and older) systems lack symlinks) in which the link file actually refers to a different file, by name. When most operations (opening, reading, writing, and so on) are passed the symbolic link file, the kernel automatically "dereferences" the link and operates on the target of the link. But some operations (e.g., removing) work on the link file itself, rather than on its target.

Examples

ln -s /some/name # creates link ./name pointing to /some/name
ln -s /some/name spud # creates link ./spud pointing to /some/name
ln -s a b .. # creates links ../a and ../b pointing to ./a and ./b


About the Author

FortyPoundHead has posted a total of 1974 articles.

 


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:54.81.197.127

Before you can post, you need to prove you are human. If you log in, this test goes away.




Recent Forum Posts

Advanced search added
dwirch posted on September 23, 2017 at about 13:44 in Site News

Job Spammer: Gaurav Mehta - AgreeYa Solutions
dwirch posted on September 22, 2017 at about 10:35 in Spammers

Job Spammer: Prutha Siri - Javelin Systems
dwirch posted on September 10, 2017 at about 6:15 in Spammers

New security implemented
dwirch posted on September 7, 2017 at about 7:16 in Site News

Malicious IP Checker Companion Tool
dwirch posted on August 12, 2017 at about 20:24 in Site News

Job Spammer: Steve Adams
dwirch posted on August 8, 2017 at about 7:44 in Spammers