command creates both
hard and soft (symbolic) links (18.4
Only UNIX versions with symbolic links have the -s
To create a hard link
To create a symbolic link
In either case,
must already exist. Otherwise you
will get an error message.
If you are using Berkeley UNIX,
must not exist - if it does, you will get an error.
Under System V,
may already exist; if you are
allowed to write the file, ln
destroys its old contents and
creates your link.
If you don't have write access for
asks whether or not it is OK to override the
ln foo bar
ln: override protection 444 for bar?
permission to destroy the file bar
Note that this will still fail if you don't have write
access to the directory.
You are allowed to omit the
argument from the ln
In this case, ln
takes the last component of
(i.e., everything after the last slash) and uses it
Of course, this assumes that
refer to the current directory.
If it does, the command will fail:
the link will already exist.
For example, the commands below are the same:
ln -s ../archive/file.c
ln -s ../archive/file.c file.c
Both create a link from file.c
in the current directory to
also lets you create a group of links with one command,
provided that all of the links are in the same directory.
file1 file2 file3 ... filen directory
This command uses the filename from each pathname
(after the last slash) as each link's name. It
then creates all the links within the given
For example, the first command below is equivalent to the next two:
ln ../s/f1 ../s/f2 current
ln ../s/f1 current/f1
ln ../s/f2 current/f2
You can replace this list of files with a
wildcard expression (15.2
ln -s ../newversion/*.[ch]
Note that symbolic links can
get out-of-date (18.6
[Hard links can also be "broken" in some situations.
For example, a text editor might rename the link textfile
, then create a new textfile
Previous links to textfile
will now give you textfile.bak
To track down this problem,
find the links (17.22
to each file.
To remove a link, either hard or symbolic, use the rm