fix bug that can cause recursive .forward files to fail
[unix-history] / usr / src / bin / ln / ln.1
CommitLineData
afe13027
KB
1.\" Copyright (c) 1980, 1990, 1993
2.\" The Regents of the University of California. All rights reserved.
8b99182b 3.\"
cf136d2c
KB
4.\" This code is derived from software contributed to Berkeley by
5.\" the Institute of Electrical and Electronics Engineers, Inc.
6.\"
3d98c418 7.\" %sccs.include.redist.roff%
8b99182b 8.\"
afe13027 9.\" @(#)ln.1 8.1 (Berkeley) %G%
d9d7a9f0
CL
10.\"
11.Dd
12.Dt LN 1
13.Os BSD 4
14.Sh NAME
15.Nm ln
16.Nd make links
17.Sh SYNOPSIS
18.Nm ln
022efdf4 19.Op Fl fs
5325ced3
CL
20.Ar source_file
21.Op target_file
d9d7a9f0 22.Nm ln
022efdf4 23.Op Fl fs
5325ced3
CL
24.Ar source_file ...
25.Op target_dir
d9d7a9f0
CL
26.Sh DESCRIPTION
27The
28.Nm ln
022efdf4
EA
29utility creates a new directory entry (linked file) which has the
30same modes as the orginal file.
31It is useful for maintaining multiple copies of a file in many places
32at once without using up storage for the
33.Dq copies ;
34instead, a link
35.Dq points
36to the original copy.
5325ced3 37There are two types of links; hard links and symbolic links.
022efdf4
EA
38How a link
39.Dq points
40to a file is one of the differences between a hard or symbolic link.
5325ced3 41.Pp
022efdf4 42The options are as follows:
3d98c418 43.Bl -tag -width flag
022efdf4
EA
44.It Fl f
45Unlink any already existing file, permitting the link to occur.
3d98c418 46.It Fl s
5325ced3 47Create a symbolic link.
3d98c418 48.El
d9d7a9f0 49.Pp
da202ae8 50By default
d9d7a9f0
CL
51.Nm ln
52makes
53.Em hard
54links.
022efdf4
EA
55A hard link to a file is indistinguishable from the original directory entry;
56any changes to a file are effective independent of the name used to reference
57the file.
58Hard links may not normally refer to directories and may not span file systems.
d9d7a9f0 59.Pp
da202ae8
KM
60A symbolic link contains the name of the file to
61which it is linked. The referenced file is used when an
d9d7a9f0 62.Xr open 2
da202ae8
KM
63operation is performed on the link.
64A
d9d7a9f0 65.Xr stat 2
da202ae8 66on a symbolic link will return the linked-to file; an
d9d7a9f0 67.Xr lstat 2
da202ae8
KM
68must be done to obtain information about the link.
69The
d9d7a9f0 70.Xr readlink 2
da202ae8
KM
71call may be used to read the contents of a symbolic link.
72Symbolic links may span file systems and may refer to directories.
d9d7a9f0 73.Pp
8b99182b 74Given one or two arguments,
d9d7a9f0 75.Nm ln
8b99182b 76creates a link to an existing file
d9d7a9f0 77.Ar source_file .
8b99182b 78If
d9d7a9f0 79.Ar target_file
8b99182b 80is given, the link has that name;
d9d7a9f0 81.Ar target_file
8b99182b
KM
82may also be a directory in which to place the link;
83otherwise it is placed in the current directory.
da202ae8
KM
84If only the directory is specified, the link will be made
85to the last component of
d9d7a9f0
CL
86.Ar source_file .
87.Pp
8b99182b 88Given more than two arguments,
d9d7a9f0
CL
89.Nm ln
90makes links in
91.Ar target_dir
9f0d4865 92to all the named source files.
8b99182b 93The links made will have the same name as the files being linked to.
d9d7a9f0 94.Sh SEE ALSO
d9d7a9f0 95.Xr link 2 ,
5a77d711 96.Xr lstat 2 ,
d9d7a9f0
CL
97.Xr readlink 2 ,
98.Xr stat 2 ,
0d17b9a2
KB
99.Xr symlink 2 ,
100.Xr symlink 7
d9d7a9f0
CL
101.Sh HISTORY
102A
103.Nm ln
3d98c418
CL
104command appeared in
105.At v6 .