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.11 (Berkeley) 07/24/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 Rfhip 17.Ar source_file target_file 18.Nm cp 19.Op Fl Rfhip 20.Ar source_file ... target_directory 21.Sh DESCRIPTION 22In the first synopsis form, the 23.Nm cp 24utility copies the contents of the 25.Ar source_file 26to the 27.Ar target_file . 28In the second synopsis form, 29the contents of each named 30.Ar source_file 31is copied to the destination 32.Ar target_directory . 33The names of the files themselves are not changed. 34If 35.Nm cp 36detects an attempt to copy a file to itself, the copy will fail. 37.Pp 38The following options are available: 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.) 49.Tp Fl h 50Forces 51.Nm cp 52to follow symbolic links. 53Provided for the 54.Fl R 55option which does not follow symbolic links by default. 56.Tp Fl i 57Causes 58.Nm cp 59to write a prompt to standard error before copying a file that would 60overwrite an existing file. 61If the response from the standard input begins with the character 62.Sq Li y , 63the file is copied if permissions allow the copy. 64.Tp Fl p 65Causes 66.Nm cp 67to preserve in the copy as many of the modification time, access time, 68file mode, user ID, and group ID as allowed by permissions. 69.Pp 70If the user ID and group ID cannot be preserved, no error message 71is displayed and the exit value is not altered. 72.Pp 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. 83.Tp Fl R 84If 85.Ar source_file 86designates a directory, 87.Nm cp 88copies the directory and the entire subtree connected at that point. 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. 93Created directories have the same mode as the corresponding source 94directory, unmodified by the process' umask. 95.Tp 96.Pp 97For each destination file that already exists, its contents are 98overwritten if permissions allow, but its mode, user ID, and group 99ID are unchanged. 100.Pp 101If the destination file does not exist, the mode of the source file is 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. 114.Pp 115Appropriate permissions are required for file creation or overwriting. 116.Pp 117Symbolic links are followed unless the 118.Fl R 119option is specified, in which case the link itself is copied. 120.Pp 121.Nm Cp 122exits 0 on success, >0 if an error occurred. 123.Sh SEE ALSO 124.Xr mv 1 , 125.Xr rcp 1 , 126.Xr umask 2 , 127.Xr csh 1 128.Sh HISTORY 129The 130.Nm cp 131command appeared in Version 6 AT&T UNIX. 132