add .Vx so tmac.andoc will call tmac.mdoc-old
[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.\"
5325ced3 6.\" @(#)cp.1 6.11 (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
5325ced3 16.Op Fl Rfhip
b5dc1377 17.Ar source_file target_file
b5dc1377 18.Nm cp
3c3c3fc0 19.Op Fl Rfhip
b5dc1377
CL
20.Ar source_file ... target_directory
21.Sh DESCRIPTION
5325ced3 22In the first synopsis form, the
b5dc1377
CL
23.Nm cp
24utility copies the contents of the
25.Ar source_file
26to the
5325ced3
CL
27.Ar target_file .
28In the second synopsis form,
b5dc1377 29the contents of each named
5325ced3 30.Ar source_file
b5dc1377
CL
31is copied to the destination
32.Ar target_directory .
33The names of the files themselves are not changed.
a783899b 34If
b5dc1377 35.Nm cp
24e5a125 36detects an attempt to copy a file to itself, the copy will fail.
5325ced3 37.Pp
a783899b 38The following options are available:
5325ced3
CL
39.Tw Ds
40.Tp Fl f
41For each existing destination pathname, remove it and
42create a new file, without prompting for confirmation
43regardless of its permissions.
44(The
45.Fl i
46option is ignored if the
47.Fl f
48option is specified.)
b5dc1377 49.Tp Fl h
a783899b 50Forces
b5dc1377 51.Nm cp
a783899b 52to follow symbolic links.
24e5a125 53Provided for the
3c3c3fc0 54.Fl R
24e5a125 55option which does not follow symbolic links by default.
b5dc1377 56.Tp Fl i
a783899b 57Causes
b5dc1377 58.Nm cp
a783899b
KB
59to write a prompt to standard error before copying a file that would
60overwrite an existing file.
5325ced3
CL
61If the response from the standard input begins with the character
62.Sq Li y ,
63the file is copied if permissions allow the copy.
b5dc1377 64.Tp Fl p
a783899b 65Causes
b5dc1377 66.Nm cp
a783899b
KB
67to preserve in the copy as many of the modification time, access time,
68file mode, user ID, and group ID as allowed by permissions.
b5dc1377 69.Pp
c942f008
KB
70If the user ID and group ID cannot be preserved, no error message
71is displayed and the exit value is not altered.
b5dc1377 72.Pp
5325ced3
CL
73If the source file has its set user ID bit on and the user ID cannot
74be preserved, the set user ID bit is not preserved
75in the copy's permissions.
76If the source file has its set group ID bit on and the group ID cannot
77be preserved, the set group ID bit is not preserved
78in the copy's permissions.
79If the source file has both the set user ID and set group ID bits
80on and either the user ID or group ID cannot be preserved, neither
81the set user ID or set group ID bits are preserved in the copy's
82permissions.
3c3c3fc0 83.Tp Fl R
a783899b 84If
b5dc1377 85.Ar source_file
a783899b 86designates a directory,
b5dc1377 87.Nm cp
a783899b 88copies the directory and the entire subtree connected at that point.
5325ced3
CL
89This option also causes symbolic links to be copied, rather than
90indirected through, and for
91.Nm cp
92to create special files rather than copying them as normal files.
24e5a125 93Created directories have the same mode as the corresponding source
5325ced3 94directory, unmodified by the process' umask.
b5dc1377
CL
95.Tp
96.Pp
97For each destination file that already exists, its contents are
5325ced3
CL
98overwritten if permissions allow, but its mode, user ID, and group
99ID are unchanged.
b5dc1377
CL
100.Pp
101If the destination file does not exist, the mode of the source file is
5325ced3
CL
102used as modified by the file mode creation mask
103.Pf \&( Ic umask ,
104see
105.Xr csh 1 ) .
106If the source file has its set user ID bit on, that bit is removed
107unless both the source file and the destination file are owned by the
108same user.
109If the source file has its set group ID bit on, that bit is removed
110unless both the source file and the destination file are in the same
111group and the user is a member of that group.
112If both the set user ID and set group ID bits are set, all of the above
113conditions must be fulfilled or both bits are removed.
b5dc1377
CL
114.Pp
115Appropriate permissions are required for file creation or overwriting.
116.Pp
5325ced3
CL
117Symbolic links are followed unless the
118.Fl R
119option is specified, in which case the link itself is copied.
120.Pp
b5dc1377 121.Nm Cp
a783899b 122exits 0 on success, >0 if an error occurred.
b5dc1377
CL
123.Sh SEE ALSO
124.Xr mv 1 ,
125.Xr rcp 1 ,
5325ced3
CL
126.Xr umask 2 ,
127.Xr csh 1
b5dc1377
CL
128.Sh HISTORY
129The
130.Nm cp
131command appeared in Version 6 AT&T UNIX.