xref: /original-bsd/bin/cp/cp.1 (revision e58c8952)
1.\" Copyright (c) 1989, 1990, 1993, 1994
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.\"	@(#)cp.1	8.3 (Berkeley) 04/18/94
10.\"
11.Dd
12.Dt CP 1
13.Os BSD 4
14.Sh NAME
15.Nm cp
16.Nd copy files
17.Sh SYNOPSIS
18.Nm cp
19.Oo
20.Fl R
21.Op Fl H | Fl L | Fl P
22.Oc
23.Op Fl fip
24.Ar source_file target_file
25.Nm cp
26.Oo
27.Fl R
28.Op Fl H | Fl L | Fl P
29.Oc
30.Op Fl fip
31.Ar source_file ... target_directory
32.Sh DESCRIPTION
33In the first synopsis form, the
34.Nm cp
35utility copies the contents of the
36.Ar source_file
37to the
38.Ar target_file .
39In the second synopsis form,
40the contents of each named
41.Ar source_file
42is copied to the destination
43.Ar target_directory .
44The names of the files themselves are not changed.
45If
46.Nm cp
47detects an attempt to copy a file to itself, the copy will fail.
48.Pp
49The following options are available:
50.Bl -tag -width flag
51.It Fl H
52If the
53.Fl R
54option is specified, symbolic links on the command line are followed.
55(Symbolic links encountered in the tree traversal are not followed.)
56.It Fl L
57If the
58.Fl R
59option is specified, all symbolic links are followed.
60.It Fl P
61If the
62.Fl R
63option is specified, no symbolic links are followed.
64.It Fl R
65If
66.Ar source_file
67designates a directory,
68.Nm cp
69copies the directory and the entire subtree connected at that point.
70This option also causes symbolic links to be copied, rather than
71indirected through, and for
72.Nm cp
73to create special files rather than copying them as normal files.
74Created directories have the same mode as the corresponding source
75directory, unmodified by the process' umask.
76.It Fl f
77For each existing destination pathname, remove it and
78create a new file, without prompting for confirmation
79regardless of its permissions.
80(The
81.Fl i
82option is ignored if the
83.Fl f
84option is specified.)
85.It Fl i
86Causes
87.Nm cp
88to write a prompt to the standard error output before copying a file
89that would overwrite an existing file.
90If the response from the standard input begins with the character
91.Sq Li y ,
92the file copy is attempted.
93.It Fl p
94Causes
95.Nm cp
96to preserve in the copy as many of the modification time, access time,
97file flags, file mode, user ID, and group ID as allowed by permissions.
98.Pp
99If the user ID and group ID cannot be preserved, no error message
100is displayed and the exit value is not altered.
101.Pp
102If the source file has its set user ID bit on and the user ID cannot
103be preserved, the set user ID bit is not preserved
104in the copy's permissions.
105If the source file has its set group ID bit on and the group ID cannot
106be preserved, the set group ID bit is not preserved
107in the copy's permissions.
108If the source file has both its set user ID and set group ID bits on,
109and either the user ID or group ID cannot be preserved, neither
110the set user ID or set group ID bits are preserved in the copy's
111permissions.
112.El
113.Pp
114For each destination file that already exists, its contents are
115overwritten if permissions allow, but its mode, user ID, and group
116ID are unchanged.
117.Pp
118In the second synopsis form,
119.Ar target_directory
120must exist unless there is only one named
121.Ar source_file
122which is a directory and the
123.Fl R
124flag is specified.
125.Pp
126If the destination file does not exist, the mode of the source file is
127used as modified by the file mode creation mask
128.Pf ( Ic umask ,
129see
130.Xr csh 1 ) .
131If the source file has its set user ID bit on, that bit is removed
132unless both the source file and the destination file are owned by the
133same user.
134If the source file has its set group ID bit on, that bit is removed
135unless both the source file and the destination file are in the same
136group and the user is a member of that group.
137If both the set user ID and set group ID bits are set, all of the above
138conditions must be fulfilled or both bits are removed.
139.Pp
140Appropriate permissions are required for file creation or overwriting.
141.Pp
142Symbolic links are always followed unless the
143.Fl R
144flag is set, in which case symbolic links are not followed, by default.
145The
146.Fl H
147or
148.Fl L
149flags (in conjunction with the
150.Fl R
151flag) cause symbolic links to be followed as described above.
152The
153.Fl H ,
154.Fl L
155and
156.Fl P
157options are ignored unless the
158.Fl R
159option is specified.
160In addition, these options override each other and the
161command's actions are determined by the last one specified.
162.Pp
163.Nm Cp
164exits 0 on success, >0 if an error occurred.
165.Sh COMPATIBILITY
166Historic versions of the
167.Nm cp
168utility had a
169.Fl r
170option.
171This implementation supports that option, however, its use is strongly
172discouraged, as it does not correctly copy special files, symbolic links
173or fifo's.
174.Sh SEE ALSO
175.Xr mv 1 ,
176.Xr rcp 1 ,
177.Xr umask 2 ,
178.Xr fts 3 ,
179.Xr symlink 7
180.Sh HISTORY
181The
182.Nm cp
183command is expected to be
184.St -p1003.2
185compatible.
186