1.\" $OpenBSD: cp.1,v 1.25 2004/12/10 10:23:30 jmc Exp $ 2.\" $NetBSD: cp.1,v 1.9 1995/07/25 19:36:45 jtc Exp $ 3.\" 4.\" Copyright (c) 1989, 1990, 1993, 1994 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" This code is derived from software contributed to Berkeley by 8.\" the Institute of Electrical and Electronics Engineers, Inc. 9.\" 10.\" Redistribution and use in source and binary forms, with or without 11.\" modification, are permitted provided that the following conditions 12.\" are met: 13.\" 1. Redistributions of source code must retain the above copyright 14.\" notice, this list of conditions and the following disclaimer. 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in the 17.\" documentation and/or other materials provided with the distribution. 18.\" 3. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.\" @(#)cp.1 8.3 (Berkeley) 4/18/94 35.\" 36.Dd April 18, 1994 37.Dt CP 1 38.Os 39.Sh NAME 40.Nm cp 41.Nd copy files 42.Sh SYNOPSIS 43.Nm cp 44.Op Fl fip 45.Oo 46.Fl R 47.Op Fl H | L | P 48.Oc 49.Ar source_file target_file 50.Nm cp 51.Op Fl fip 52.Oo 53.Fl R 54.Op Fl H | L | P 55.Oc 56.Ar source_file ... target_directory 57.Sh DESCRIPTION 58In the first synopsis form, the 59.Nm 60utility copies the contents of the 61.Ar source_file 62to the 63.Ar target_file . 64In the second synopsis form, 65the contents of each named 66.Ar source_file 67are copied to the destination 68.Ar target_directory . 69The names of the files themselves are not changed. 70If 71.Nm 72detects an attempt to copy a file to itself, the copy will fail. 73.Pp 74The options are as follows: 75.Bl -tag -width Ds 76.It Fl f 77For each existing destination pathname, remove it and 78create a new file, without prompting for confirmation, 79regardless of its permissions. 80This option overrides any use of 81.Fl i . 82.It Fl H 83If the 84.Fl R 85option is also specified, symbolic links on the command-line are followed. 86(Symbolic links encountered in the tree traversal are not followed.) 87.It Fl i 88Write a prompt to the standard error output before copying a file 89that would overwrite an existing file. 90If the response from the standard input begins with the character 91.Sq Li y , 92the file copy is attempted. 93.It Fl L 94If the 95.Fl R 96option is also specified, all symbolic links are followed. 97.It Fl P 98If the 99.Fl R 100option is also specified, no symbolic links are followed. 101.It Fl p 102Preserve in the copy as many of the modification time, access time, 103file flags, file mode, user ID, and group ID as allowed by permissions. 104.Pp 105If the user ID and group ID cannot be preserved, no error message 106is displayed and the exit value is not altered. 107.Pp 108If the source file has its set-user-ID bit on and the user ID cannot 109be preserved, the set-user-ID bit is not preserved 110in the copy's permissions. 111If the source file has its set-group-ID bit on and the group ID cannot 112be preserved, the set-group-ID bit is not preserved 113in the copy's permissions. 114If the source file has both its set-user-ID and set-group-ID bits on, 115and either the user ID or group ID cannot be preserved, neither 116the set-user-ID nor set-group-ID bits are preserved in the copy's 117permissions. 118.It Fl R 119If 120.Ar source_file 121designates a directory, 122.Nm 123copies the directory and the entire subtree connected at that point. 124Created directories have the same mode as the corresponding source 125directory, unmodified by the process's umask. 126.Pp 127This option also causes symbolic links to be copied, rather than 128followed, and 129special files to be created, rather than being copied as normal files. 130However, 131.Nm 132copies hard linked files as separate files. 133To preserve hard links, 134use a utility such as 135.Xr pax 1 136or 137.Xr tar 1 138instead. 139.El 140.Pp 141For each destination file that already exists, its contents are 142overwritten if permissions allow, but its mode, user ID, and group 143ID are unchanged. 144.Pp 145In the second synopsis form, 146.Ar target_directory 147must exist unless there is only one named 148.Ar source_file 149which is a directory and the 150.Fl R 151flag is specified. 152.Pp 153If the destination file does not exist, the mode of the source file is 154used as modified by the file mode creation mask 155.Pf ( Ic umask , 156see 157.Xr csh 1 ) . 158If the source file has its set-user-ID bit on, that bit is removed 159unless both the source file and the destination file are owned by the 160same user. 161If the source file has its set-group-ID bit on, that bit is removed 162unless both the source file and the destination file are in the same 163group and the user is a member of that group. 164If both the set-user-ID and set-group-ID bits are set, all of the above 165conditions must be fulfilled or both bits are removed. 166.Pp 167Appropriate permissions are required for file creation or overwriting. 168.Pp 169Symbolic links are always followed unless the 170.Fl R 171flag is set, in which case symbolic links are not followed, by default. 172The 173.Fl H 174or 175.Fl L 176flags (in conjunction with the 177.Fl R 178flag) cause symbolic links to be followed as described above. 179The 180.Fl H , 181.Fl L , 182and 183.Fl P 184options are ignored unless the 185.Fl R 186option is specified. 187In addition, these options override each other and the 188command's actions are determined by the last one specified. 189.Pp 190The 191.Nm 192utility exits 0 on success or >0 if an error occurred. 193.Sh EXAMPLES 194Make a copy of file 195.Pa foo 196named 197.Pa bar : 198.Pp 199.Dl $ cp foo bar 200.Pp 201Copy a group of files to the 202.Pa /tmp 203directory: 204.Pp 205.Dl $ cp *.txt /tmp 206.Pp 207Copy the directory 208.Pa junk 209and all of its contents (including any subdirectories) to the 210.Pa /tmp 211directory: 212.Pp 213.Dl $ cp -R junk /tmp 214.Sh SEE ALSO 215.Xr mv 1 , 216.Xr rcp 1 , 217.Xr umask 2 , 218.Xr fts 3 , 219.Xr symlink 7 220.Sh STANDARDS 221Historic versions of the 222.Nm 223utility had a 224.Fl r 225option. 226This implementation supports that option; however, its use is strongly 227discouraged, as it does not correctly copy special files, symbolic links 228or FIFOs. 229.Pp 230The 231.Nm 232utility is expected to be 233.St -p1003.2 234compatible. 235.Sh HISTORY 236A 237.Nm 238command appeared in 239.At v1 . 240