View | Details | Raw Unified | Return to bug 44074
Collapse All | Expand All

(-)/tmp/ln.1 (-40 / +65 lines)
Lines 41-78 Link Here
41
.Sh NAME
41
.Sh NAME
42
.Nm ln ,
42
.Nm ln ,
43
.Nm link
43
.Nm link
44
.Nd make links
44
.Nd make soft links (symbolic links, symlinks) and hard links
45
.Sh SYNOPSIS
45
.Sh SYNOPSIS
46
.Nm
46
.Nm
47
.Op Fl fhinsv
47
.Op Fl fhinsv
48
.Ar source_file
48
.Ar to_filename
49
.Op Ar target_file
49
.Op Ar from_filename
50
.Nm
50
.Nm
51
.Op Fl fhinsv
51
.Op Fl fhinsv
52
.Ar source_file ...
52
.Ar to_filename ...
53
.Ar target_dir
53
.Ar dir_filename
54
.Nm link
54
.Nm link
55
.Ar source_file Ar target_file
55
.Ar to_existing_filename Ar from_alternate_filename
56
.Sh DESCRIPTION
56
.Sh DESCRIPTION
57
The
57
The
58
.Nm
58
.Nm
59
utility creates a new directory entry (linked file) which has the
59
utility creates a new filesystem entry which can refer to an existing file
60
same modes as the original file.
60
.Pq or multiple such entries with the second form .
61
It is useful for maintaining multiple copies of a file in many places
61
It is useful for maintaining multiple virtual copies of a file in many places
62
at once without using up storage for the
62
while using filesystem storage for only one file.
63
.Dq copies ;
63
Two types of links may be made:
64
instead, a link
64
.Nm ln
65
.Dq points
65
can make 
66
to the original copy.
66
.Em soft links
67
There are two types of links; hard links and symbolic links.
67
or
68
How a link
68
.Em hard links ,
69
.Dq points
69
while
70
to a file is one of the differences between a hard and symbolic link.
70
.Nm link
71
can make only hard links.
72
Note that soft links are also called
73
.Em symbolic links
74
and
75
.Em symlinks .
76
The two types are described following the option descriptions.
71
.Pp
77
.Pp
72
The options are as follows:
78
The options are as follows:
73
.Bl -tag -width flag
79
.Bl -tag -width flag
74
.It Fl f
80
.It Fl f
75
If the target file already exists,
81
If the 
82
.Qq from
83
file already exists,
76
then unlink it so that the link may occur.
84
then unlink it so that the link may occur.
77
(The
85
(The
78
.Fl f
86
.Fl f
Lines 81-101 Link Here
81
options.)
89
options.)
82
.It Fl h
90
.It Fl h
83
If the
91
If the
84
.Ar target_file
92
.Ar from_filename
85
or
93
or
86
.Ar target_dir
94
.Ar dir_filename
87
is a symbolic link, do not follow it.  This is most useful with the
95
is a soft link, do not follow it.  This is most useful with the
88
.Fl f
96
.Fl f
89
option, to replace a symlink which may point to a directory.
97
option, to replace a soft link which may point to a directory.
90
.It Fl i
98
.It Fl i
91
Cause
99
Cause
92
.Nm
100
.Nm
93
to write a prompt to standard error if the target file exists.
101
to write a prompt to standard error if the
102
.Qq from
103
file exists.
94
If the response from the standard input begins with the character
104
If the response from the standard input begins with the character
95
.Sq Li y
105
.Sq Li y
96
or
106
or
97
.Sq Li Y ,
107
.Sq Li Y ,
98
then unlink the target file so that the link may occur.
108
then unlink the
109
.Qq from
110
file so that the link may occur.
99
Otherwise, do not attempt the link.
111
Otherwise, do not attempt the link.
100
(The
112
(The
101
.Fl i
113
.Fl i
Lines 109-115 Link Here
109
.Nm
121
.Nm
110
implementations.
122
implementations.
111
.It Fl s
123
.It Fl s
112
Create a symbolic link.
124
Create a soft link.
113
.It Fl v
125
.It Fl v
114
Cause
126
Cause
115
.Nm
127
.Nm
Lines 118-164 Link Here
118
.Pp
130
.Pp
119
By default,
131
By default,
120
.Nm
132
.Nm
121
makes
133
makes hard links.
122
.Em hard
134
A hard link to a file is indistinguishable from the original filesystem entry;
123
links.
124
A hard link to a file is indistinguishable from the original directory entry;
125
any changes to a file are effectively independent of the name used to reference
135
any changes to a file are effectively independent of the name used to reference
126
the file.
136
the file.
137
Unlike with soft links,
138
both old and new filesystem entries become links to each other
139
.Pq and to other files to which either is hard linked .
127
Hard links may not normally refer to directories and may not span filesystems.
140
Hard links may not normally refer to directories and may not span filesystems.
128
.Pp
141
.Pp
129
A symbolic link contains the name of the file to
142
A soft link contains the name of the file to
130
which it is linked.  The referenced file is used when an
143
which it is linked.  The referenced file is used when an
131
.Xr open  2
144
.Xr open  2
132
operation is performed on the link.
145
operation is performed on the link.
133
A
146
A
134
.Xr stat  2
147
.Xr stat  2
135
on a symbolic link will return the linked-to file; an
148
on a soft link will return the linked-to file; an
136
.Xr lstat  2
149
.Xr lstat  2
137
must be done to obtain information about the link.
150
must be done to obtain information about the link.
138
The
151
The
139
.Xr readlink  2
152
.Xr readlink  2
140
call may be used to read the contents of a symbolic link.
153
call may be used to read the contents of a soft link.
141
Symbolic links may span filesystems and may refer to directories.
154
Soft links may span filesystems and may refer to directories.
142
.Pp
155
.Pp
143
Given one or two arguments,
156
Given one or two arguments,
144
.Nm
157
.Nm
145
creates a link to an existing file
158
creates a link to an existing file
146
.Ar source_file  .
159
.Ar to_filename  .
147
If
160
If
148
.Ar target_file
161
.Ar from_filename
149
is given, the link has that name;
162
is given, the link has that name;
150
.Ar target_file
163
.Ar from_filename
151
may also be a directory in which to place the link;
164
may also be a directory in which to place the link;
152
otherwise it is placed in the current directory.
165
otherwise it is placed in the current directory.
153
If only the directory is specified, the link will be made
166
If only the directory is specified, the link will be made
154
to the last component of
167
to the last component of
155
.Ar source_file  .
168
.Ar to_filename  .
156
.Pp
169
.Pp
157
Given more than two arguments,
170
Given more than two arguments,
158
.Nm
171
.Nm
159
makes links in
172
makes links in
160
.Ar target_dir
173
.Ar dir_filename
161
to all the named source files.
174
to all the named
175
.Qq to
176
files.
162
The links made will have the same name as the files being linked to.
177
The links made will have the same name as the files being linked to.
163
.Pp
178
.Pp
164
When the utility is called as
179
When the utility is called as
Lines 169-174 Link Here
169
which performs a
184
which performs a
170
.Xr link 2
185
.Xr link 2
171
operation using the two passed arguments.
186
operation using the two passed arguments.
187
.Sh NOTES
188
Soft links require careful use to ensure that the
189
.Qq to
190
filename is used rather than the
191
.Qq from
192
filename, and vice-versa.
193
Their handling by programs is not completely standardized.
194
Some often-followed conventions, notable exceptions,
195
and related discussion may be found in
196
.Xr symlink 7 .
172
.Sh SEE ALSO
197
.Sh SEE ALSO
173
.Xr link 2 ,
198
.Xr link 2 ,
174
.Xr lstat 2 ,
199
.Xr lstat 2 ,

Return to bug 44074