xref: /original-bsd/bin/ln/ln.1 (revision b4971bb3)
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.\" %sccs.include.redist.roff%
8.\"
9.\"	@(#)ln.1	8.1 (Berkeley) 05/31/93
10.\"
11.Dd
12.Dt LN 1
13.Os BSD 4
14.Sh NAME
15.Nm ln
16.Nd make links
17.Sh SYNOPSIS
18.Nm ln
19.Op Fl fs
20.Ar source_file
21.Op target_file
22.Nm ln
23.Op Fl fs
24.Ar source_file ...
25.Op target_dir
26.Sh DESCRIPTION
27The
28.Nm ln
29utility creates a new directory entry (linked file) which has the
30same modes as the orginal file.
31It is useful for maintaining multiple copies of a file in many places
32at once without using up storage for the
33.Dq copies ;
34instead, a link
35.Dq points
36to the original copy.
37There are two types of links; hard links and symbolic links.
38How a link
39.Dq points
40to a file is one of the differences between a hard or symbolic link.
41.Pp
42The options are as follows:
43.Bl -tag -width flag
44.It Fl f
45Unlink any already existing file, permitting the link to occur.
46.It Fl s
47Create a symbolic link.
48.El
49.Pp
50By default
51.Nm ln
52makes
53.Em hard
54links.
55A hard link to a file is indistinguishable from the original directory entry;
56any changes to a file are effective independent of the name used to reference
57the file.
58Hard links may not normally refer to directories and may not span file systems.
59.Pp
60A symbolic link contains the name of the file to
61which it is linked.  The referenced file is used when an
62.Xr open  2
63operation is performed on the link.
64A
65.Xr stat  2
66on a symbolic link will return the linked-to file; an
67.Xr lstat  2
68must be done to obtain information about the link.
69The
70.Xr readlink  2
71call may be used to read the contents of a symbolic link.
72Symbolic links may span file systems and may refer to directories.
73.Pp
74Given one or two arguments,
75.Nm ln
76creates a link to an existing file
77.Ar source_file  .
78If
79.Ar target_file
80is given, the link has that name;
81.Ar target_file
82may also be a directory in which to place the link;
83otherwise it is placed in the current directory.
84If only the directory is specified, the link will be made
85to the last component of
86.Ar source_file  .
87.Pp
88Given more than two arguments,
89.Nm ln
90makes links in
91.Ar target_dir
92to all the named source files.
93The links made will have the same name as the files being linked to.
94.Sh SEE ALSO
95.Xr link 2 ,
96.Xr lstat 2 ,
97.Xr readlink 2 ,
98.Xr stat 2 ,
99.Xr symlink 2 ,
100.Xr symlink 7
101.Sh HISTORY
102A
103.Nm ln
104command appeared in
105.At v6 .
106