.\" Copyright (c) 1989, 1990 The Regents of the University of California. .\" All rights reserved. .\" .\" %sccs.include.redist.man% .\" .\" @(#)cp.1 6.10 (Berkeley) %G% .\" .Dd .Dt CP 1 .Os BSD 4 .Sh NAME .Nm cp .Nd copy files .Sh SYNOPSIS .Nm cp .Op Fl fhip .Ar source_file target_file .br .Nm cp .Op Fl Rfhip .Ar source_file ... target_directory .Sh DESCRIPTION In the first synopsis form, .Nm cp utility copies the contents of the .Ar source_file to the .Ar target_file or, in the second synopsis form, the contents of each named .Ar source_file(s) is copied to the destination .Ar target_directory . The names of the files themselves are not changed. If .Nm cp detects an attempt to copy a file to itself, the copy will fail. The following options are available: .Tp Fl h Forces .Nm cp to follow symbolic links. Provided for the .Fl R option which does not follow symbolic links by default. .Tp Fl f Turns off the .Fl i option. (The last .Fl f or .Fl i option overrides any previous specification of either option.) .Tp Fl i Causes .Nm cp to write a prompt to standard error before copying a file that would overwrite an existing file. If the response from the standard input begins with the character ``y'', the file is copied if permissions allow. (The last .Fl f or .Fl i option overrides any previous specification of either option.) .Tp Fl p Causes .Nm cp to preserve in the copy as many of the modification time, access time, .\" and file mode as allowed by permissions. file mode, user ID, and group ID as allowed by permissions. .Pp If the user ID and group ID cannot be preserved, no error message is displayed and the exit value is not altered. .Pp If the source file is set user ID or set group ID, and either the user ID or the group ID cannot be preserved, the set user ID and set group ID bits are not preserved in the copy's permissions. .Tp Fl R If .Ar source_file designates a directory, .Nm cp copies the directory and the entire subtree connected at that point. Special file types, such as symbolic links and block and character devices, are recreated instead of being copied. Created directories have the same mode as the corresponding source directory, unmodified by the process' file mode creation mask (umask). .Tp Fl r The .Fl r option is identical to the .Fl R option with the exception that it does not treat special files differently from regular files. Symbolic links are always followed. This option has been deprecated. .Tp .Pp For each destination file that already exists, its contents are overwritten if permissions allow, but .Nm cp will not change its mode, user ID, or group ID. However, if the file is not being copied by the super-user, writing the file may clear the set user ID or set group ID permission bits. .Pp If the destination file does not exist, the mode of the source file is used as modified by the file mode creation mask (umask). If the source file is either set user ID or set group ID, those bits are removed unless the source file and the destination file are owned by the same user and group. .Pp Appropriate permissions are required for file creation or overwriting. .Pp .Nm Cp exits 0 on success, >0 if an error occurred. .Sh SEE ALSO .Xr mv 1 , .Xr rcp 1 , .Xr umask 2 .Sh HISTORY The .Nm cp command appeared in Version 6 AT&T UNIX.