xref: /openbsd/bin/ln/ln.1 (revision 133306f0)
1.\"	$OpenBSD: ln.1,v 1.10 2000/11/09 17:51:55 aaron Exp $
2.\"	$NetBSD: ln.1,v 1.10 1995/07/25 19:37:04 jtc Exp $
3.\"
4.\" Copyright (c) 1980, 1990, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" This code is derived from software contributed to Berkeley by
8.\" the Institute of Electrical and Electronics Engineers, Inc.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. All advertising materials mentioning features or use of this software
19.\"    must display the following acknowledgement:
20.\"	This product includes software developed by the University of
21.\"	California, Berkeley and its contributors.
22.\" 4. Neither the name of the University nor the names of its contributors
23.\"    may be used to endorse or promote products derived from this software
24.\"    without specific prior written permission.
25.\"
26.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36.\" SUCH DAMAGE.
37.\"
38.\"	@(#)ln.1	8.2 (Berkeley) 12/30/93
39.\"
40.Dd December 30, 1993
41.Dt LN 1
42.Os
43.Sh NAME
44.Nm ln
45.Nd make hard and symbolic links to files
46.Sh SYNOPSIS
47.Nm ln
48.Op Fl fs
49.Ar source_file
50.Op Ar target_file
51.Nm ln
52.Op Fl fs
53.Ar source_file ...
54.Op Ar target_dir
55.Sh DESCRIPTION
56The
57.Nm
58utility creates a new directory entry (linked file) which has the
59same modes as the original file.
60It is useful for maintaining multiple copies of a file in many places
61at once without using up storage for the copies;
62instead, a link
63.Dq points
64to the original copy.
65There are two types of links; hard links and symbolic links.
66How a link points
67to a file is one of the differences between a hard and symbolic link.
68.Pp
69The options are as follows:
70.Bl -tag -width Ds
71.It Fl f
72Unlink any already existing file, permitting the link to occur.
73.It Fl s
74Create a symbolic link.
75.El
76.Pp
77By default,
78.Nm
79makes
80.Dq hard
81links.
82A hard link to a file is indistinguishable from the original directory entry;
83any changes to a file are effectively independent of the name used to reference
84the file.
85Hard links may not normally refer to directories and may not span file systems.
86.Pp
87A symbolic link contains the name of the file to
88which it is linked.
89The referenced file is used when an
90.Xr open 2
91operation is performed on the link.
92A
93.Xr stat 2
94on a symbolic link will return the linked-to file; an
95.Xr lstat 2
96must be done to obtain information about the link.
97The
98.Xr readlink 2
99call may be used to read the contents of a symbolic link.
100Symbolic links may span file systems, refer to directories, and refer to
101non-existent files.
102.Pp
103Given one or two arguments,
104.Nm
105creates a link to an existing file
106.Ar source_file .
107If
108.Ar target_file
109is given, the link has that name;
110.Ar target_file
111may also be a directory in which to place the link.
112Otherwise, it is placed in the current directory.
113If only the directory is specified, the link will be made
114to the last component of
115.Ar source_file .
116.Pp
117Given more than two arguments,
118.Nm
119makes links in
120.Ar target_dir
121to all the named source files.
122The links made will have the same name as the files being linked to.
123.Sh EXAMPLES
124.Cm ln -s /var/www /home/www
125.Pp
126Creates a symbolic link named
127.Pa /home/www
128and points it to
129.Pa /var/www .
130.Pp
131.Cm ln /usr/local/bin/fooprog-1.0 /usr/local/bin/fooprog
132.Pp
133Hard link
134.Pa /usr/local/bin/fooprog
135to file
136.Pa /usr/local/bin/fooprog-1.0 .
137.Pp
138As an exercise, try the following commands:
139.Pp
140.D1 Ic $ ls -i /bin/[
141.D1 Li 11553 /bin/[
142.D1 Ic $ ls -i /bin/test
143.D1 Li 11553 /bin/test
144.Pp
145Note that both files have the same inode; that is,
146.Pa /bin/[
147is essentially an alias for the
148.Xr test 1
149command.
150This hard link exists so
151.Xr test 1
152may be invoked from shell scripts, for example, using the
153.Cm "if [ ]"
154construct.
155.Sh SEE ALSO
156.Xr link 2 ,
157.Xr lstat 2 ,
158.Xr readlink 2 ,
159.Xr stat 2 ,
160.Xr symlink 2 ,
161.Xr symlink 7
162.Sh HISTORY
163An
164.Nm
165utility appeared in
166.At v6 .
167