Professional Documents
Culture Documents
CP - F - I - P - S - e CP - F - I - P - S - e CP - F - I - P - S - R - R - e CP - R - R - H - L - P - F - I - P - S - e
CP - F - I - P - S - e CP - F - I - P - S - e CP - F - I - P - S - R - R - e CP - R - R - H - L - P - F - I - P - S - e
cp(1)
NAME
cp - copy les and directory subtrees
SYNOPSIS
cp [-f-i] [-p] [-S] [-e extarg ] le1 new_le
dest_directory
DESCRIPTION
cp copies:
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
destroyed.
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 -r option is required. The -r option 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 , modied by the le creation mask of the user if the -p option was
not specied, 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 modication 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) Causes 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
afrmative, the le is copied if permissions allow the copy.
-f
(force copy) Forces existing destination pathnames to be removed before copying, without
prompting for conrmation. This option has the effect of destroying and replacing any existing
le whose name and directory location conicts with the name and location of the new le
created by the copy operation.
When the UNIX95/UNIX2003 ag is set and if the destination le exists and the user has write
permission on the destination le, then the destination le is not removed.
-p
(preserve permissions) Causes cp to preserve in the copy as many of the modication time,
access time, le mode, user ID, and group ID as allowed by permissions.
-r
(recursive subtree copy) Causes 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
-r cannot 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
Hewlett-Packard Company
cp(1)
cp(1)
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 innite amount of data.
Under the UNIX Standard environment (see standards (5)), cp will exit with error if multiple
sources are being copied to a non-existing directory.
-R
Warning: While copying a directory tree that has device special les, use the -r option; otherwise, an innite amount of data is read from the device special le and is duplicated as a special
le in the destination directory occupying large le system space.
-H
Causes cp to traverse the symbolic link specied as an operand and copy it to the destination.
-L
Causes cp to traverse the symbolic link specied as an operand or any symbolic links encountered during traversal of a le hierarchy, and copy it to the destination.
-P
Causes cp to copy the symbolic link specied as an operand and any symbolic links encountered
during traversal of a le hierarchy. This option will not follow any symbolic links.
-e extarg
Species the handling of any extent attributes of the le[s] to be copied. extarg takes one of the
following values.
warn
ignore
force
Issues a warning message if extent attributes cannot be copied, but copies the
le anyway.
Does not copy the extent attributes.
Fails to copy the le if the extent attribute can not be copied.
Extent attributes can not be copied if the les are being copied to a le system which does not
support extent attributes or if that le system has a different block size than the original. If -e
is not specied, the default value for extarg is warn.
-S
Species "safe" mode. This option minimizes the impact of cp on the performance of the system
by opening the target le using the O_DSYNC ag. This is recommended when the total size of
the copy (not of a single le) is a signicant portion of the size of system buffer cache. Usage of
this option increases copy time.
Specifying more than one of the mutually-exclusive options -H, -L, and -P will not be considered an
error. The last option specied will determine the behavior of the utility.
Access Control Lists (ACLs)
If new_le is a new le, or if a new le is created in dest_directory, it inherits the access control list of the
original le1 , le2 , etc., altered to reect any difference in ownership between the two les (see acl (5)
and aclv (5)). In JFS le systems, new les created by cp do not inherit their parent directorys default
ACL entries (if any), but instead retain the ACLs of the les being copied. When copying les from a JFS
le system to an HFS le system or vice versa, optional ACL entries are lost.
EXTERNAL INFLUENCES
For information about the UNIX standard environment, see standards (5).
Environment Variables
LC_CTYPE determines the interpretation of text as single and/or multi-byte characters.
LANG and LC_CTYPE determine the local language equivalent of y (for yes/no queries).
LANG determines the language in which messages are displayed.
If LC_CTYPE is not specied in the environment or is set to the empty string, the value of LANG is used
as a default for each unspecied or empty variable. If LANG is not specied or is set to the empty string,
a default of "C" (see lang (5)) is used instead of LANG. If any internationalization variable contains an
invalid setting, cp behaves as if all internationalization variables are set to "C". See environ (5).
Hewlett-Packard Company
cp(1)
cp(1)
mv sourcedir targetdir
To copy all les and directory subtrees in the current directory to an existing targetdir , use:
cp -r * targetdir
To copy all les and directory subtrees in sourcedir to targetdir , use:
cp -r sourcedir /* targetdir
Note that directory pathnames can precede both sourcedir and targetdir .
To create a zero-length le, use any of the following:
Hewlett-Packard Company
(Notes)
(Notes)
Hewlett-Packard Company