4.4BSD snapshot (revision 8.1)
[unix-history] / usr / src / bin / cp / cp.1
CommitLineData
ba5e8546
KB
1.\" Copyright (c) 1989, 1990, 1993
2.\" The Regents of the University of California. All rights reserved.
c4c58dfe 3.\"
cf136d2c
KB
4.\" This code is derived from software contributed to Berkeley by
5.\" the Institute of Electrical and Electronics Engineers, Inc.
6.\"
c4a7b8ab 7.\" %sccs.include.redist.roff%
a783899b 8.\"
ba5e8546 9.\" @(#)cp.1 8.1 (Berkeley) %G%
c4c58dfe 10.\"
b5dc1377
CL
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
04e69296 19.Op Fl HRfhip
b5dc1377 20.Ar source_file target_file
b5dc1377 21.Nm cp
04e69296 22.Op Fl HRfhip
b5dc1377
CL
23.Ar source_file ... target_directory
24.Sh DESCRIPTION
5325ced3 25In the first synopsis form, the
b5dc1377
CL
26.Nm cp
27utility copies the contents of the
28.Ar source_file
29to the
5325ced3
CL
30.Ar target_file .
31In the second synopsis form,
b5dc1377 32the contents of each named
5325ced3 33.Ar source_file
b5dc1377
CL
34is copied to the destination
35.Ar target_directory .
36The names of the files themselves are not changed.
a783899b 37If
b5dc1377 38.Nm cp
24e5a125 39detects an attempt to copy a file to itself, the copy will fail.
5325ced3 40.Pp
a783899b 41The following options are available:
c4a7b8ab 42.Bl -tag -width flag
04e69296
EA
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.
50e548fa
EA
46Provided for the
47.Fl R
48option which does not follow symbolic links by default.
0e853b88
CL
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
5325ced3
CL
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.)
0e853b88 70.It Fl h
04e69296 71When encountering a symbolic link anywhere in the traversal, follow it.
24e5a125 72Provided for the
3c3c3fc0 73.Fl R
24e5a125 74option which does not follow symbolic links by default.
0e853b88 75.It Fl i
a783899b 76Causes
b5dc1377 77.Nm cp
e8865dd0 78to write a prompt to the standard error output before copying a file that would
a783899b 79overwrite an existing file.
5325ced3
CL
80If the response from the standard input begins with the character
81.Sq Li y ,
82the file is copied if permissions allow the copy.
0e853b88 83.It Fl p
a783899b 84Causes
b5dc1377 85.Nm cp
a783899b 86to preserve in the copy as many of the modification time, access time,
a7b841a8 87file flags, file mode, user ID, and group ID as allowed by permissions.
b5dc1377 88.Pp
c942f008
KB
89If the user ID and group ID cannot be preserved, no error message
90is displayed and the exit value is not altered.
b5dc1377 91.Pp
5325ced3
CL
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.
e8865dd0
KM
98If the source file has both its set user ID and set group ID bits on,
99and either the user ID or group ID cannot be preserved, neither
5325ced3
CL
100the set user ID or set group ID bits are preserved in the copy's
101permissions.
0e853b88 102.El
b5dc1377
CL
103.Pp
104For each destination file that already exists, its contents are
5325ced3
CL
105overwritten if permissions allow, but its mode, user ID, and group
106ID are unchanged.
b5dc1377 107.Pp
feb92fe6
EA
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
b5dc1377 116If the destination file does not exist, the mode of the source file is
5325ced3 117used as modified by the file mode creation mask
c4a7b8ab 118.Pf ( Ic umask ,
5325ced3
CL
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.
b5dc1377
CL
129.Pp
130Appropriate permissions are required for file creation or overwriting.
131.Pp
50e548fa
EA
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
04e69296
EA
136.Fl H
137or
138.Fl h
50e548fa
EA
139flags (in conjuction with the
140.Fl R
141flag) cause symbolic link following as detailed above.
5325ced3 142.Pp
b5dc1377 143.Nm Cp
a783899b 144exits 0 on success, >0 if an error occurred.
b5dc1377
CL
145.Sh SEE ALSO
146.Xr mv 1 ,
147.Xr rcp 1 ,
50e548fa 148.Xr umask 2 ,
0d17b9a2
KB
149.Xr fts 3 ,
150.Xr symlink 7
b5dc1377
CL
151.Sh HISTORY
152The
153.Nm cp
c4a7b8ab
CL
154command is expected to be
155.St -p1003.2
156compatible.