lncreate a link to a file |
Command |
ln
[-fiRrv
] old new
ln
[-fiRrsv
] old old ... dir
ln
creates a link to a file or set of files. A link
is a new directory entry that refers to the same file, either in the directory
that currently contains the file or in a different directory. The result is a
new path name that refers to the file. You can access the file under the old
path name or the new one; both path names are of equal importance. If you
rm
either name, the other one remains
and the file contents are still available under that name. The contents of the
file do not disappear until you remove the last link.
A file may have any number of links to it. Thus you can establish any number of
different path names for any file.
In the first form given in the synopsis, new becomes a new path name for
the file old. In the second form, ln
creates entries
for all the old files under the directory dir. For example,
creates links underln yourdir/* mydir
mydir
to all the files under
yourdir
. The files have the same names under mydir
that they had under yourdir
. ln
always assumes
this directory form when the last operand on the command line is the name of a
directory. In this case, none of the old names may be a directory.
In some cases a file may have the same name as the link you are trying to set up.
This file is referred to as the conflicting path name. To deal
with a conflicting path name, ln
follows these steps.
-i
, ln
writes a prompt to standard error to ask if you want to remove the
conflicting path name. If you answer affirmatively, ln
attempts to remove it.-f
, ln
attempts to remove the conflict silently.ln
prints a diagnostic message.ln
attempts to do so in the same way that
rm
does. ln
deletes the file associated with the path name if this path name is the last
link to the file. If ln
can't get rid of the conflicting
path name, it does not attempt to establish the new link; it simply prints
an error message on the standard error and goes on to process any other
files.ln
successfully removes the conflicting path name,
it then establishes the link.-f
removes conflicting path names without asking for confirmation.
-i
checks with you before getting rid of conflicting path names. (Note
that the -f
option overrides the -i
option.)
-R
links files recursively; that is, you can link an entire hierarchy of subdirectories at once.
-r
is identical to -R
.
-s
creates a symbolic link.
-v
shows file names as they are processed.
0
All requested links were established successfully.
1
Failure due to any of the following:
/
but was not the name of a
directory-r
-r
-r
-r
-r
2
Failure due to any of the following:
-f
option is part of the POSIX standard.