make consistent with POSIX 1003.2, draft 10. Now have two recursive
[unix-history] / usr / src / bin / cp / cp.1
CommitLineData
b5dc1377 1.\" Copyright (c) 1989, 1990 The Regents of the University of California.
a783899b 2.\" All rights reserved.
c4c58dfe 3.\"
27c71911 4.\" %sccs.include.redist.man%
a783899b 5.\"
3c3c3fc0 6.\" @(#)cp.1 6.10 (Berkeley) %G%
c4c58dfe 7.\"
b5dc1377
CL
8.Dd
9.Dt CP 1
10.Os BSD 4
11.Sh NAME
12.Nm cp
13.Nd copy files
14.Sh SYNOPSIS
15.Nm cp
16.Op Fl fhip
17.Ar source_file target_file
18.br
19.Nm cp
3c3c3fc0 20.Op Fl Rfhip
b5dc1377
CL
21.Ar source_file ... target_directory
22.Sh DESCRIPTION
23In the first synopsis form,
24.Nm cp
25utility copies the contents of the
26.Ar source_file
27to the
28.Ar target_file
29or, in the second synopsis form,
30the contents of each named
31.Ar source_file(s)
32is copied to the destination
33.Ar target_directory .
34The names of the files themselves are not changed.
a783899b 35If
b5dc1377 36.Nm cp
24e5a125 37detects an attempt to copy a file to itself, the copy will fail.
a783899b 38The following options are available:
b5dc1377 39.Tp Fl h
a783899b 40Forces
b5dc1377 41.Nm cp
a783899b 42to follow symbolic links.
24e5a125 43Provided for the
3c3c3fc0 44.Fl R
24e5a125 45option which does not follow symbolic links by default.
b5dc1377 46.Tp Fl f
3c3c3fc0 47Turns off the
b5dc1377 48.Fl i
3c3c3fc0
KB
49option.
50(The last
b5dc1377 51.Fl f
3c3c3fc0
KB
52or
53.Fl i
54option overrides any previous specification of either option.)
b5dc1377 55.Tp Fl i
a783899b 56Causes
b5dc1377 57.Nm cp
a783899b
KB
58to write a prompt to standard error before copying a file that would
59overwrite an existing file.
60If the response from the standard input begins with the character ``y'',
3c3c3fc0
KB
61the file is copied if permissions allow.
62(The last
63.Fl f
64or
65.Fl i
66option overrides any previous specification of either option.)
b5dc1377 67.Tp Fl p
a783899b 68Causes
b5dc1377 69.Nm cp
a783899b 70to preserve in the copy as many of the modification time, access time,
24e5a125 71.\" and file mode as allowed by permissions.
a783899b 72file mode, user ID, and group ID as allowed by permissions.
b5dc1377 73.Pp
c942f008
KB
74If the user ID and group ID cannot be preserved, no error message
75is displayed and the exit value is not altered.
b5dc1377 76.Pp
3c3c3fc0
KB
77If the source file is set user ID or set group ID, and either the user
78ID or the group ID cannot be preserved, the set user ID and set group
79ID bits are not preserved in the copy's permissions.
80.Tp Fl R
a783899b 81If
b5dc1377 82.Ar source_file
a783899b 83designates a directory,
b5dc1377 84.Nm cp
a783899b 85copies the directory and the entire subtree connected at that point.
3c3c3fc0
KB
86Special file types, such as symbolic links and block and character
87devices, are recreated instead of being copied.
24e5a125 88Created directories have the same mode as the corresponding source
3c3c3fc0
KB
89directory, unmodified by the process' file mode creation mask (umask).
90.Tp Fl r
91The
92.Fl r
93option is identical to the
94.Fl R
95option with the exception that it does not treat special files
96differently from regular files.
97Symbolic links are always followed.
98This option has been deprecated.
b5dc1377
CL
99.Tp
100.Pp
101For each destination file that already exists, its contents are
3c3c3fc0
KB
102overwritten if permissions allow, but
103.Nm cp
104will not change its mode, user ID, or group ID.
105However, if the file is not being copied by the super-user,
106writing the file may clear the set user ID or set group ID
107permission bits.
b5dc1377
CL
108.Pp
109If the destination file does not exist, the mode of the source file is
110used as modified by the file mode creation mask (umask).
3c3c3fc0
KB
111If the source file is either set user ID or set group ID, those
112bits are removed unless the source file and the destination
113file are owned by the same user and group.
b5dc1377
CL
114.Pp
115Appropriate permissions are required for file creation or overwriting.
116.Pp
b5dc1377 117.Nm Cp
a783899b 118exits 0 on success, >0 if an error occurred.
b5dc1377
CL
119.Sh SEE ALSO
120.Xr mv 1 ,
121.Xr rcp 1 ,
122.Xr umask 2
123.Sh HISTORY
124The
125.Nm cp
126command appeared in Version 6 AT&T UNIX.