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