ln - link files


ln [-fs] source_file target_file
ln [-fs] source_file... target_dir


The ln(1) utility creates a new directory entry (linked file) that has the same modes as the original file. It is useful for maintaining multiple copies of a file in many places at once without using up storage for the "copies"; instead, a link "points" to the original copy. There are two types of links: hard links and symbolic links. How a link points to a file is one of the differences between a hard or symbolic link.

The options are as follows:

Unlink any already existing file, permitting the link to occur.
Create a symbolic link.

By default, the ln(1) utility makes hard links. A hard link to a file is indistinguishable from the original directory entry; changes to a file take effect regardless of the name used to refer to the file. Hard links cannot normally refer to directories or span file systems.

A symbolic link contains the name of the file to which it is linked. The referenced file is used when an open(3) operation is performed on the link. A stat(3) on a symbolic link will return the linked-to file. To obtain information about the links, use lstat(3). Unlike hard links, symbolic links can refer to directories and span file systems.

Given one or two arguments, ln(1) creates a link to an existing file source_file. If target_file is given, the link has that name; target_file can also be a directory in which the link is placed; otherwise, it is placed in the current directory. If only the directory is specified, the link will be made to the last component of source_file.

Given more than two arguments, ln(1) makes links in target_dir to all the named source files. The links will have the same name as the files to which they are linking. One cannot hard link a directory.


The ln(1) utility exits 0 on success, and >0 if an error occurs.

It will return with a code of 0 and the diagnostic message

ln: filename: permission denied
if you attempt to link a file on a file-allocation table (FAT) file system.


The ln(1) command requires support from the underlying file system; it will not work on files on a FAT file system. As of Interix 2.2, the ln(1) command will work on some network drives, but success is not guaranteed.