|
Lines 41-105
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 hard links and symbolic links (symlinks, soft 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 Brq ... Ar directory_name | Op Ar from_filename |
| 49 |
.Op Ar target_file |
|
|
| 50 |
.Nm |
| 51 |
.Op Fl fhinsv |
| 52 |
.Ar source_file ... |
| 53 |
.Ar target_dir |
| 54 |
.Nm link |
49 |
.Nm link |
| 55 |
.Ar source_file Ar target_file |
50 |
.Ar to_filename Brq Ar directory_name | Ar from_filename |
| 56 |
.Sh DESCRIPTION |
51 |
.Sh DESCRIPTION |
| 57 |
The |
52 |
The |
| 58 |
.Nm |
53 |
.Nm |
| 59 |
utility creates a new directory entry (linked file) which has the |
54 |
command creates new directory entries |
| 60 |
same modes as the original file. |
55 |
which generally refer to existing files |
| 61 |
It is useful for maintaining multiple copies of a file in many places |
56 |
so that each file may be accessed by another filename, |
| 62 |
at once without using up storage for the |
57 |
possibly in another directory or filesystem. |
| 63 |
.Dq copies ; |
58 |
.\"so that multiple virtual copies of a file can exist |
| 64 |
instead, a link |
59 |
.\"while using storage for only one file. |
| 65 |
.Dq points |
60 |
The |
| 66 |
to the original copy. |
61 |
.Nm link |
| 67 |
There are two types of links; hard links and symbolic links. |
62 |
command is equivalent to |
| 68 |
How a link |
63 |
.Nm , |
| 69 |
.Dq points |
64 |
except that it must have exactly two arguments and no options; |
| 70 |
to a file is one of the differences between a hard and symbolic link. |
65 |
therefore, it is not described further. |
| 71 |
.Pp |
66 |
.Pp |
| 72 |
The options are as follows: |
67 |
Two types of links may be created: |
| 73 |
.Bl -tag -width flag |
68 |
.Em hard links |
|
|
69 |
by default, and |
| 70 |
.Em symbolic links |
| 71 |
when the |
| 72 |
.Fl s |
| 73 |
option is used. |
| 74 |
Symbolic links are often called |
| 75 |
.Em symlinks |
| 76 |
or sometimes |
| 77 |
.Em soft links . |
| 78 |
The two types are described following these option descriptions |
| 79 |
(in which the |
| 80 |
.Qq from |
| 81 |
file (i.e., link) to be created can be |
| 82 |
.Ar from_filename |
| 83 |
or a file in the |
| 84 |
.Ar directory_name |
| 85 |
directory): |
| 86 |
.Bl -tag -width ".Fl f" |
| 74 |
.It Fl f |
87 |
.It Fl f |
| 75 |
If the target file already exists, |
88 |
If the |
| 76 |
then unlink it so that the link may occur. |
89 |
.Qq from |
|
|
90 |
file already exists, then replace it. |
| 77 |
(The |
91 |
(The |
| 78 |
.Fl f |
92 |
.Fl f |
| 79 |
option overrides any previous |
93 |
option cancels any previous |
| 80 |
.Fl i |
94 |
.Fl i |
| 81 |
options.) |
95 |
options.) |
| 82 |
.It Fl h |
96 |
.It Fl h |
| 83 |
If the |
97 |
If |
| 84 |
.Ar target_file |
98 |
.Ar directory_name |
| 85 |
or |
99 |
is a symlink to a directory, do not follow it. This is useful with the |
| 86 |
.Ar target_dir |
|
|
| 87 |
is a symbolic link, do not follow it. This is most useful with the |
| 88 |
.Fl f |
100 |
.Fl f |
| 89 |
option, to replace a symlink which may point to a directory. |
101 |
option, to replace the symlink. |
|
|
102 |
(By definition, |
| 103 |
.Ar from_filename |
| 104 |
is a file or a symlink to a file, which is never followed by |
| 105 |
.Nm . ) |
| 90 |
.It Fl i |
106 |
.It Fl i |
| 91 |
Cause |
107 |
Cause |
| 92 |
.Nm |
108 |
.Nm |
| 93 |
to write a prompt to standard error if the target file exists. |
109 |
to write a prompt to standard error if the |
|
|
110 |
.Qq from |
| 111 |
file exists. |
| 94 |
If the response from the standard input begins with the character |
112 |
If the response from the standard input begins with the character |
| 95 |
.Sq Li y |
113 |
.Sq Li y |
| 96 |
or |
114 |
or |
| 97 |
.Sq Li Y , |
115 |
.Sq Li Y , |
| 98 |
then unlink the target file so that the link may occur. |
116 |
then remove the |
|
|
117 |
.Qq from |
| 118 |
file so that the link may occur. |
| 99 |
Otherwise, do not attempt the link. |
119 |
Otherwise, do not attempt the link. |
| 100 |
(The |
120 |
(The |
| 101 |
.Fl i |
121 |
.Fl i |
| 102 |
option overrides any previous |
122 |
option cancels any previous |
| 103 |
.Fl f |
123 |
.Fl f |
| 104 |
options.) |
124 |
options.) |
| 105 |
.It Fl n |
125 |
.It Fl n |
|
Lines 109-177
Link Here
|
| 109 |
.Nm |
129 |
.Nm |
| 110 |
implementations. |
130 |
implementations. |
| 111 |
.It Fl s |
131 |
.It Fl s |
| 112 |
Create a symbolic link. |
132 |
Create a symlink, instead of a hard link. |
| 113 |
.It Fl v |
133 |
.It Fl v |
| 114 |
Cause |
134 |
Cause |
| 115 |
.Nm |
135 |
.Nm |
| 116 |
to be verbose, showing files as they are processed. |
136 |
to be verbose, showing files as they are processed. |
| 117 |
.El |
137 |
.El |
| 118 |
.Pp |
138 |
.Pp |
| 119 |
By default, |
139 |
Hard links to a file are indistinguishable from the file and from each other, |
| 120 |
.Nm |
140 |
except for the filenames; |
| 121 |
makes |
141 |
in fact, each file in a filesystem appears as one or more hard link |
| 122 |
.Em hard |
142 |
directory entries by which the file's data may be accessed. |
| 123 |
links. |
143 |
All of a file's hard links have the same file owner, group, modes, and flags, |
| 124 |
A hard link to a file is indistinguishable from the original directory entry; |
144 |
and changes made to one effect them all identically, |
| 125 |
any changes to a file are effectively independent of the name used to reference |
145 |
except that removing one hard link leaves the others uneffected |
| 126 |
the file. |
146 |
until the last hard link is removed, removing the file's data too. |
| 127 |
Hard links may not normally refer to directories and may not span filesystems. |
147 |
A hard link cannot be created for a file on another filesystem nor (with |
|
|
148 |
.Nm ) |
| 149 |
for a directory. |
| 150 |
(But note that the |
| 151 |
.Qq \&. |
| 152 |
and |
| 153 |
.Qq \&.. |
| 154 |
directories appear as hard links.) |
| 128 |
.Pp |
155 |
.Pp |
| 129 |
A symbolic link contains the name of the file to |
156 |
Symlinks contain the filename of a directory or file |
| 130 |
which it is linked. The referenced file is used when an |
157 |
which may be on any filesystem (or which may not exist, |
|
|
158 |
a feature which is sometimes utilized |
| 159 |
to store miscellaneous data in a directory entry). |
| 160 |
Symlinks to one file may have different owners, groups, modes, and flags, |
| 161 |
and are not effected by changes or removal of the file or other symlinks. |
| 162 |
.Ss "Command Forms" |
| 163 |
.Bl -tag -width "" |
| 164 |
.It Nm Ar to_filename |
| 165 |
That creates a link to |
| 166 |
.Ar to_filename |
| 167 |
from |
| 168 |
.Ar basename , |
| 169 |
where the latter is the base name |
| 170 |
.Xr ( basename 1 ) |
| 171 |
of |
| 172 |
.Ar to_filename . |
| 173 |
.It Nm Ar to_filename Ar from_filename |
| 174 |
That creates a link to |
| 175 |
.Ar to_filename |
| 176 |
from |
| 177 |
.Ar from_filename . |
| 178 |
.It Nm Ar to_filename Ar ... Ar directory_name |
| 179 |
That create links to one or more instances of |
| 180 |
.Ar to_filename |
| 181 |
from one or more corresponding instances of |
| 182 |
.Ar directory_name/basename |
| 183 |
where |
| 184 |
.Ar basename |
| 185 |
is the base name |
| 186 |
.Xr ( basename 1 ) |
| 187 |
of the corresponding |
| 188 |
.Ar to_filename . |
| 189 |
.El |
| 190 |
.Sh "NOTES" |
| 191 |
The handling of symlinks by other programs is not well standardized |
| 192 |
and tends to be poorly documented for seldom-used cases; |
| 193 |
e.g., some follow the symlink if its name is followed by |
| 194 |
.Qq / . |
| 195 |
See the |
| 196 |
.Xr symlink 7 |
| 197 |
manpage for some often-followed conventions, |
| 198 |
notable exceptions, and related discussion. |
| 199 |
.Pp |
| 200 |
Hard links are created with |
| 201 |
.Xr link 2 . |
| 202 |
Symlinks are created with |
| 203 |
.Xr symlink 2 . |
| 204 |
When used on symlinks, the |
| 131 |
.Xr open 2 |
205 |
.Xr open 2 |
| 132 |
operation is performed on the link. |
206 |
and |
| 133 |
A |
|
|
| 134 |
.Xr stat 2 |
207 |
.Xr stat 2 |
| 135 |
on a symbolic link will return the linked-to file; an |
208 |
functions operate on the linked-to file, while |
| 136 |
.Xr lstat 2 |
209 |
.Xr lstat 2 |
| 137 |
must be done to obtain information about the link. |
210 |
will access information about the symlink. |
| 138 |
The |
211 |
The |
| 139 |
.Xr readlink 2 |
212 |
.Xr readlink 2 |
| 140 |
call may be used to read the contents of a symbolic link. |
213 |
call may be used to read the contents of a symlink. |
| 141 |
Symbolic links may span filesystems and may refer to directories. |
|
|
| 142 |
.Pp |
| 143 |
Given one or two arguments, |
| 144 |
.Nm |
| 145 |
creates a link to an existing file |
| 146 |
.Ar source_file . |
| 147 |
If |
| 148 |
.Ar target_file |
| 149 |
is given, the link has that name; |
| 150 |
.Ar target_file |
| 151 |
may also be a directory in which to place the link; |
| 152 |
otherwise it is placed in the current directory. |
| 153 |
If only the directory is specified, the link will be made |
| 154 |
to the last component of |
| 155 |
.Ar source_file . |
| 156 |
.Pp |
| 157 |
Given more than two arguments, |
| 158 |
.Nm |
| 159 |
makes links in |
| 160 |
.Ar target_dir |
| 161 |
to all the named source files. |
| 162 |
The links made will have the same name as the files being linked to. |
| 163 |
.Pp |
| 164 |
When the utility is called as |
| 165 |
.Nm link , |
| 166 |
exactly two arguments must be supplied, |
| 167 |
neither of which may specify a directory. |
| 168 |
No options may be supplied in this simple mode of operation, |
| 169 |
which performs a |
| 170 |
.Xr link 2 |
| 171 |
operation using the two passed arguments. |
| 172 |
.Sh SEE ALSO |
214 |
.Sh SEE ALSO |
|
|
215 |
.Xr basename 1 , |
| 173 |
.Xr link 2 , |
216 |
.Xr link 2 , |
| 174 |
.Xr lstat 2 , |
217 |
.Xr lstat 2 , |
|
|
218 |
.Xr open 2 , |
| 175 |
.Xr readlink 2 , |
219 |
.Xr readlink 2 , |
| 176 |
.Xr stat 2 , |
220 |
.Xr stat 2 , |
| 177 |
.Xr symlink 2 , |
221 |
.Xr symlink 2 , |
|
Lines 183-199
Link Here
|
| 183 |
.Fl n |
227 |
.Fl n |
| 184 |
and |
228 |
and |
| 185 |
.Fl v |
229 |
.Fl v |
| 186 |
options are non-standard and their use in scripts is not recommended. |
230 |
options are non-standard and their omission from scripts is recommended. |
| 187 |
They are provided solely for compatibility with other |
231 |
They are provided solely for compatibility with other |
| 188 |
.Nm |
232 |
.Nm |
| 189 |
implementations. |
233 |
implementations. |
| 190 |
.Sh STANDARDS |
234 |
.Sh STANDARDS |
| 191 |
The |
235 |
The |
| 192 |
.Nm |
236 |
.Nm |
| 193 |
utility conforms to |
237 |
command conforms to |
| 194 |
.St -p1003.2-92 . |
238 |
.St -p1003.2-92 . |
| 195 |
.Pp |
239 |
.Pp |
| 196 |
The simplified |
240 |
The |
| 197 |
.Nm link |
241 |
.Nm link |
| 198 |
command conforms to |
242 |
command conforms to |
| 199 |
.St -susv2 . |
243 |
.St -susv2 . |