xref: /original-bsd/bin/cp/cp.1 (revision 92ab646d)
1.\" Copyright (c) 1989, 1990 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)cp.1	6.10 (Berkeley) 06/29/90
7.\"
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
20.Op Fl Rfhip
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.
35If
36.Nm cp
37detects an attempt to copy a file to itself, the copy will fail.
38The following options are available:
39.Tp Fl h
40Forces
41.Nm cp
42to follow symbolic links.
43Provided for the
44.Fl R
45option which does not follow symbolic links by default.
46.Tp Fl f
47Turns off the
48.Fl i
49option.
50(The last
51.Fl f
52or
53.Fl i
54option overrides any previous specification of either option.)
55.Tp Fl i
56Causes
57.Nm cp
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'',
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.)
67.Tp Fl p
68Causes
69.Nm cp
70to preserve in the copy as many of the modification time, access time,
71.\" and file mode as allowed by permissions.
72file mode, user ID, and group ID as allowed by permissions.
73.Pp
74If the user ID and group ID cannot be preserved, no error message
75is displayed and the exit value is not altered.
76.Pp
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
81If
82.Ar source_file
83designates a directory,
84.Nm cp
85copies the directory and the entire subtree connected at that point.
86Special file types, such as symbolic links and block and character
87devices, are recreated instead of being copied.
88Created directories have the same mode as the corresponding source
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.
99.Tp
100.Pp
101For each destination file that already exists, its contents are
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.
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).
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.
114.Pp
115Appropriate permissions are required for file creation or overwriting.
116.Pp
117.Nm Cp
118exits 0 on success, >0 if an error occurred.
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.
127