xref: /original-bsd/bin/cp/cp.1 (revision a1c2194a)
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.man%
8.\"
9.\"     @(#)cp.1	6.14 (Berkeley) 06/27/91
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 Rfhip
20.Ar source_file target_file
21.Nm cp
22.Op Fl Rfhip
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 4n
43.It Fl R
44If
45.Ar source_file
46designates a directory,
47.Nm cp
48copies the directory and the entire subtree connected at that point.
49This option also causes symbolic links to be copied, rather than
50indirected through, and for
51.Nm cp
52to create special files rather than copying them as normal files.
53Created directories have the same mode as the corresponding source
54directory, unmodified by the process' umask.
55.It Fl f
56For each existing destination pathname, remove it and
57create a new file, without prompting for confirmation
58regardless of its permissions.
59(The
60.Fl i
61option is ignored if the
62.Fl f
63option is specified.)
64.It Fl h
65Forces
66.Nm cp
67to follow symbolic links.
68Provided for the
69.Fl R
70option which does not follow symbolic links by default.
71.It Fl i
72Causes
73.Nm cp
74to write a prompt to standard error before copying a file that would
75overwrite an existing file.
76If the response from the standard input begins with the character
77.Sq Li y ,
78the file is copied if permissions allow the copy.
79.It Fl p
80Causes
81.Nm cp
82to preserve in the copy as many of the modification time, access time,
83file mode, user ID, and group ID as allowed by permissions.
84.Pp
85If the user ID and group ID cannot be preserved, no error message
86is displayed and the exit value is not altered.
87.Pp
88If the source file has its set user ID bit on and the user ID cannot
89be preserved, the set user ID bit is not preserved
90in the copy's permissions.
91If the source file has its set group ID bit on and the group ID cannot
92be preserved, the set group ID bit is not preserved
93in the copy's permissions.
94If the source file has both the set user ID and set group ID bits
95on and either the user ID or group ID cannot be preserved, neither
96the set user ID or set group ID bits are preserved in the copy's
97permissions.
98.El
99.Pp
100For each destination file that already exists, its contents are
101overwritten if permissions allow, but its mode, user ID, and group
102ID are unchanged.
103.Pp
104If the destination file does not exist, the mode of the source file is
105used as modified by the file mode creation mask
106.Pf \&( Ic umask ,
107see
108.Xr csh 1 ) .
109If the source file has its set user ID bit on, that bit is removed
110unless both the source file and the destination file are owned by the
111same user.
112If the source file has its set group ID bit on, that bit is removed
113unless both the source file and the destination file are in the same
114group and the user is a member of that group.
115If both the set user ID and set group ID bits are set, all of the above
116conditions must be fulfilled or both bits are removed.
117.Pp
118Appropriate permissions are required for file creation or overwriting.
119.Pp
120Symbolic links are followed unless the
121.Fl R
122option is specified, in which case the link itself is copied.
123.Pp
124.Nm Cp
125exits 0 on success, >0 if an error occurred.
126.Sh SEE ALSO
127.Xr mv 1 ,
128.Xr rcp 1 ,
129.Xr umask 2
130.Sh HISTORY
131The
132.Nm cp
133command is expected to be POSIX 1003.2 compatible.
134