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