xref: /freebsd/bin/ln/ln.1 (revision 5d053f461caeb73f6de165aa1e07b2003101605c)
1.\"-
2.\" Copyright (c) 1980, 1990, 1993
3.\"	The Regents of the University of California.  All rights reserved.
4.\"
5.\" This code is derived from software contributed to Berkeley by
6.\" the Institute of Electrical and Electronics Engineers, Inc.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"	@(#)ln.1	8.2 (Berkeley) 12/30/93
33.\" $FreeBSD$
34.\"
35.Dd June 6, 2008
36.Dt LN 1
37.Os
38.Sh NAME
39.Nm ln ,
40.Nm link
41.Nd make links
42.Sh SYNOPSIS
43.Nm
44.Op Fl s Op Fl F
45.Op Fl f | iw
46.Op Fl hnv
47.Ar source_file
48.Op Ar target_file
49.Nm
50.Op Fl s Op Fl F
51.Op Fl f | iw
52.Op Fl hnv
53.Ar source_file ...
54.Ar target_dir
55.Nm link
56.Ar source_file Ar target_file
57.Sh DESCRIPTION
58The
59.Nm
60utility creates a new directory entry (linked file) which has the
61same modes as the original file.
62It is useful for maintaining multiple copies of a file in many places
63at once without using up storage for the
64.Dq copies ;
65instead, a link
66.Dq points
67to the original copy.
68There are two types of links; hard links and symbolic links.
69How a link
70.Dq points
71to a file is one of the differences between a hard and symbolic link.
72.Pp
73The options are as follows:
74.Bl -tag -width flag
75.It Fl f
76If the target file already exists,
77then unlink it so that the link may occur.
78(The
79.Fl f
80option overrides any previous
81.Fl i
82and
83.Fl w
84options.)
85.It Fl F
86If the target file already exists and is a directory, then remove it
87so that the link may occur.
88The
89.Fl F
90option should be used with either
91.Fl f
92or
93.Fl i
94options.
95If none is specified,
96.Fl f
97is implied.
98The
99.Fl F
100option is a no-op unless
101.Fl s
102option is specified.
103.It Fl h
104If the
105.Ar target_file
106or
107.Ar target_dir
108is a symbolic link, do not follow it.
109This is most useful with the
110.Fl f
111option, to replace a symlink which may point to a directory.
112.It Fl i
113Cause
114.Nm
115to write a prompt to standard error if the target file exists.
116If the response from the standard input begins with the character
117.Sq Li y
118or
119.Sq Li Y ,
120then unlink the target file so that the link may occur.
121Otherwise, do not attempt the link.
122(The
123.Fl i
124option overrides any previous
125.Fl f
126options.)
127.It Fl n
128Same as
129.Fl h ,
130for compatibility with other
131.Nm
132implementations.
133.It Fl s
134Create a symbolic link.
135.It Fl v
136Cause
137.Nm
138to be verbose, showing files as they are processed.
139.It Fl w
140Warn if the source of a symbolic link does not currently exist.
141.El
142.Pp
143By default,
144.Nm
145makes
146.Em hard
147links.
148A hard link to a file is indistinguishable from the original directory entry;
149any changes to a file are effectively independent of the name used to reference
150the file.
151Hard links may not normally refer to directories and may not span file systems.
152.Pp
153A symbolic link contains the name of the file to
154which it is linked.
155The referenced file is used when an
156.Xr open 2
157operation is performed on the link.
158A
159.Xr stat 2
160on a symbolic link will return the linked-to file; an
161.Xr lstat 2
162must be done to obtain information about the link.
163The
164.Xr readlink 2
165call may be used to read the contents of a symbolic link.
166Symbolic links may span file systems and may refer to directories.
167.Pp
168Given one or two arguments,
169.Nm
170creates a link to an existing file
171.Ar source_file .
172If
173.Ar target_file
174is given, the link has that name;
175.Ar target_file
176may also be a directory in which to place the link;
177otherwise it is placed in the current directory.
178If only the directory is specified, the link will be made
179to the last component of
180.Ar source_file .
181.Pp
182Given more than two arguments,
183.Nm
184makes links in
185.Ar target_dir
186to all the named source files.
187The links made will have the same name as the files being linked to.
188.Pp
189When the utility is called as
190.Nm link ,
191exactly two arguments must be supplied,
192neither of which may specify a directory.
193No options may be supplied in this simple mode of operation,
194which performs a
195.Xr link 2
196operation using the two passed arguments.
197.Sh COMPATIBILITY
198The
199.Fl h ,
200.Fl i ,
201.Fl n ,
202.Fl v
203and
204.Fl w
205options are non-standard and their use in scripts is not recommended.
206They are provided solely for compatibility with other
207.Nm
208implementations.
209.Pp
210The
211.Fl F
212option is
213.Fx
214extention and should not be used in portable scripts.
215.Sh SEE ALSO
216.Xr link 2 ,
217.Xr lstat 2 ,
218.Xr readlink 2 ,
219.Xr stat 2 ,
220.Xr symlink 2 ,
221.Xr symlink 7
222.Sh STANDARDS
223The
224.Nm
225utility conforms to
226.St -p1003.2-92 .
227.Pp
228The simplified
229.Nm link
230command conforms to
231.St -susv2 .
232.Sh HISTORY
233An
234.Nm
235command appeared in
236.At v1 .
237