xref: /original-bsd/bin/cp/cp.1 (revision c98fd05d)
1.\" Copyright (c) 1989, 1990 The Regents of the University of California.
2.\" 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	6.21 (Berkeley) 07/27/92
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.Op Fl HRfhip
20.Ar source_file target_file
21.Nm cp
22.Op Fl HRfhip
23.Ar source_file ... target_directory
24.Sh DESCRIPTION
25In the first synopsis form, the
26.Nm cp
27utility copies the contents of the
28.Ar source_file
29to the
30.Ar target_file .
31In the second synopsis form,
32the contents of each named
33.Ar source_file
34is copied to the destination
35.Ar target_directory .
36The names of the files themselves are not changed.
37If
38.Nm cp
39detects an attempt to copy a file to itself, the copy will fail.
40.Pp
41The following options are available:
42.Bl -tag -width flag
43.It Fl H
44When encountering a symbolic link on the command line, follow it.  All other
45symbolic links encountered in the traversal are not followed.
46Provided for the
47.Fl R
48option which does not follow symbolic links by default.
49.It Fl R
50If
51.Ar source_file
52designates a directory,
53.Nm cp
54copies the directory and the entire subtree connected at that point.
55This option also causes symbolic links to be copied, rather than
56indirected through, and for
57.Nm cp
58to create special files rather than copying them as normal files.
59Created directories have the same mode as the corresponding source
60directory, unmodified by the process' umask.
61.It Fl f
62For each existing destination pathname, remove it and
63create a new file, without prompting for confirmation
64regardless of its permissions.
65(The
66.Fl i
67option is ignored if the
68.Fl f
69option is specified.)
70.It Fl h
71When encountering a symbolic link anywhere in the traversal, follow it.
72Provided for the
73.Fl R
74option which does not follow symbolic links by default.
75.It Fl i
76Causes
77.Nm cp
78to write a prompt to standard error before copying a file that would
79overwrite an existing file.
80If the response from the standard input begins with the character
81.Sq Li y ,
82the file is copied if permissions allow the copy.
83.It Fl p
84Causes
85.Nm cp
86to preserve in the copy as many of the modification time, access time,
87file flags, file mode, user ID, and group ID as allowed by permissions.
88.Pp
89If the user ID and group ID cannot be preserved, no error message
90is displayed and the exit value is not altered.
91.Pp
92If the source file has its set user ID bit on and the user ID cannot
93be preserved, the set user ID bit is not preserved
94in the copy's permissions.
95If the source file has its set group ID bit on and the group ID cannot
96be preserved, the set group ID bit is not preserved
97in the copy's permissions.
98If the source file has both the set user ID and set group ID bits
99on and either the user ID or group ID cannot be preserved, neither
100the set user ID or set group ID bits are preserved in the copy's
101permissions.
102.El
103.Pp
104For each destination file that already exists, its contents are
105overwritten if permissions allow, but its mode, user ID, and group
106ID are unchanged.
107.Pp
108In the second synopsis form,
109.Ar target_directory
110must exist unless there is only one named
111.Ar source_file
112which is a directory and the
113.Fl R
114flag is specified.
115.Pp
116If the destination file does not exist, the mode of the source file is
117used as modified by the file mode creation mask
118.Pf ( Ic umask ,
119see
120.Xr csh 1 ) .
121If the source file has its set user ID bit on, that bit is removed
122unless both the source file and the destination file are owned by the
123same user.
124If the source file has its set group ID bit on, that bit is removed
125unless both the source file and the destination file are in the same
126group and the user is a member of that group.
127If both the set user ID and set group ID bits are set, all of the above
128conditions must be fulfilled or both bits are removed.
129.Pp
130Appropriate permissions are required for file creation or overwriting.
131.Pp
132Symbolic links are always followed unless the
133.Fl R
134flag is set in which case symbolic links are not followed by default.
135However, the
136.Fl H
137or
138.Fl h
139flags (in conjuction with the
140.Fl R
141flag) cause symbolic link following as detailed above.
142.Pp
143.Nm Cp
144exits 0 on success, >0 if an error occurred.
145.Sh SEE ALSO
146.Xr mv 1 ,
147.Xr rcp 1 ,
148.Xr umask 2 ,
149.Xr fts 3 ,
150.Xr symlink 7
151.Sh HISTORY
152The
153.Nm cp
154command is expected to be
155.St -p1003.2
156compatible.
157