c

cp(1)

cp(1)

NAME

cp - copy ®les and directory subtrees

SYNOPSIS

cp [-f-i][-p][-eextarg ] ®le1 new_®le

cp [-f-i][-p][-eextarg ] ®le1 [®le2 ... ] dest_directory

cp [-f-i][-p][-R-r][-eextarg ] directory1 [ directory2 ... ] dest_directory

DESCRIPTION

cp copies:

®le1 to new or existing new_®le,

®le1 to existing dest_directory,

®le1, ®le2, ... to existing dest_directory,

directory subtree directory1, to new or existing dest_directory. or

multiple directory subtrees directory1, directory2, ... to new or existing dest_directory.

cp fails if ®le1 and new_®le are the same (be cautious when using shell metacharacters). When destination is a directory, one or more ®les are copied into that directory. If two or more ®les are copied, the destination must be a directory. When copying a single ®le to a new ®le, if new_®le exists, its contents are des- troyed.

If the access permissions of the destination dest_directory or existing destination ®le new_®le forbid writing, cp aborts and produces an error message ``cannot create ®le''.

To copy one or more directory subtrees to another directory, the -roption is required. The -roption is ignored if used when copying a ®le to another ®le or ®les to a directory.

If new_®le is a link to an existing ®le with other links, cp overwrites the existing ®le and retains all links. If copying a ®le to an existing ®le, cp does not change existing ®le access permission bits, owner, or group.

When copying ®les to a directory or to a new ®le that does not already exist, cp creates a new ®le with the same ®le permission bits as ®le1, modi®ed by the ®le creation mask of the user if the -poption was not speci®ed, and then bitwise inclusively ORed with S_IRWXU. The owner and group of the new ®le or ®les are those of the user. The last modi®cation time of new_®le (and last access time, if new_®le did not exist) and the last access time of the source ®le1 are set to the time the copy was made.

Options

-i(interactive copy) Cause cp to write a prompt to standard error and wait for a response before copying a ®le that would overwrite an existing ®le. If the response from the standard input is af®rmative, the ®le is copied if permissions allow the copy. If the -i(interactive) and -f(forced-copy) options are both speci®ed, the -ioption is ignored.

-fForce existing destination pathnames to be removed before copying, without prompting for con®rmation. This option has the effect of destroying and replacing any existing ®le whose name and directory location con¯icts with the name and location of the new ®le created by the copy operation.

-p(preserve permissions) Causes cp to preserve in the copy as many of the modi®cation time, access time, ®le mode, user ID, and group ID as allowed by permissions.

-r(recursive subtree copy) Cause cp to copy the subtree rooted at each source directory to dest_directory. If dest_directory exists, it must be a directory, in which case cp creates a directory within dest_directory with the same name as ®le1 and copies the subtree rooted at ®le1 to dest_directory/®le1. An error occurs if dest_directory/®le1 already exists. If dest_directory does not exist, cp creates it and copies the subtree rooted at ®le1 to dest_directory. Note that cp -rcannot merge subtrees.

Usually normal ®les and directories are copied. Character special devices, block special devices, network special ®les, named pipes, symbolic links, and sockets are copied, if the user has access to the ®le; otherwise, a warning is printed stating that the ®le cannot be created, and the ®le is skipped.

dest_directory should not reside within directory1, nor should directory1 have a cyclic directory structure, since in both cases cp attempts to copy an in®nite amount of data.

Section 1114

− 1 −

HP-UX Release 11i: December 2000