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.9 (Berkeley) 06/11/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 fhipr 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 47Force existing destination pathnames to be truncated before copying, 48without prompting for confirmation. 49(The 50.Fl i 51option is ignored if the 52.Fl f 53option is specified.) 54.Tp Fl i 55Causes 56.Nm cp 57to write a prompt to standard error before copying a file that would 58overwrite an existing file. 59If the response from the standard input begins with the character ``y'', 60the file is copied if permissions allow the copy. 61.Tp Fl p 62Causes 63.Nm cp 64to preserve in the copy as many of the modification time, access time, 65.\" and file mode as allowed by permissions. 66file mode, user ID, and group ID as allowed by permissions. 67.Pp 68If the user ID and group ID cannot be preserved, no error message 69is displayed and the exit value is not altered. 70.Pp 71If the source file has its set user ID bit on and the user ID cannot 72be preserved, the set user ID bit is not preserved 73in the copy's permissions. 74If the source file has its set group ID bit on and the group ID cannot 75be preserved, the set group ID bit is not preserved 76in the copy's permissions. 77If the source file has both the set user ID and set group ID bits 78on and either the user ID or group ID cannot be preserved, neither 79the set user ID or set group ID bits are preserved in the copy's 80permissions. 81.Tp Fl r 82If 83.Ar source_file 84designates a directory, 85.Nm cp 86copies the directory and the entire subtree connected at that point. 87This option also causes symbolic links to be copied, rather than 88indirected through, and for 89.Nm cp 90to create special files rather than copying them as normal files. 91Created directories have the same mode as the corresponding source 92directory, unmodified by the process' umask. 93.Tp 94.Pp 95For each destination file that already exists, its contents are 96overwritten if permissions allow, but its mode, user ID, and group 97ID are unchanged. 98.Pp 99If the destination file does not exist, the mode of the source file is 100used as modified by the file mode creation mask (umask). 101If the source file has its set user ID bit on, that bit is removed 102unless both the source file and the destination file are owned by the 103same user. 104If the source file has its set group ID bit on, that bit is removed 105unless both the source file and the destination file are in the same 106group and the user is a member of that group. 107If both the set user ID and set group ID bits are set, all of the above 108conditions must be fulfilled or both bits are removed. 109.Pp 110Appropriate permissions are required for file creation or overwriting. 111.Pp 112Symbolic links are followed unless the 113.Fl r 114option is specified, in which case the link itself is copied. 115.Pp 116.Nm Cp 117exits 0 on success, >0 if an error occurred. 118.Sh SEE ALSO 119.Xr mv 1 , 120.Xr rcp 1 , 121.Xr umask 2 122.Sh HISTORY 123The 124.Nm cp 125command appeared in Version 6 AT&T UNIX. 126