cp — copy files and directory subtrees
directory1 [directory2 ...]
to new or existing
to new or existing
multiple directory subtrees
to new or existing
are the same (be cautious when using shell metacharacters).
When destination is a directory,
one or more files are copied into that directory.
If two or more files are copied,
the destination must be a directory.
When copying a single file to a new file, if
exists, its contents are destroyed.
If the access permissions of the destination
or existing destination file
aborts and produces an error message "cannot create
To copy one or more directory subtrees to another directory, the
option is required.
option is ignored if used when copying
a file to another file or files to a directory.
is a link to an existing file with other links,
overwrites the existing file and retains all links.
If copying a file to an existing file,
does not change existing file access
permission bits, owner, or group.
When copying files to a directory or to a new file
that does not already exist,
creates a new file with the same file permission bits as
modified by the file creation mask of the user if the
option was not specified, and then bitwise inclusively ORed with
The owner and group of the new file or files are those of the user.
The last modification time of
(and last access time, if
did not exist) and the last access time of the source
are set to the time the copy was made.
(interactive copy) Causes
to write a prompt to standard error and wait for a response
before copying a file that would overwrite an existing file.
If the response from the standard input is affirmative,
the file is copied if permissions allow the copy.
(force copy) If the destination file exists and if the user does not have
the write permission on the destination file, then this option
has the effect of destroying and replacing any existing file
whose name and directory location conflicts with the name and
location of the new file created by the copy operation.
(preserve permissions) Causes
to preserve in the copy as many of the modification time,
access time, file mode, user
as allowed by permissions.
(recursive subtree copy) Causes
to copy the subtree rooted at each source directory to
exists, it must be a directory, in which case
creates a directory within
with the same name as
and copies the subtree rooted at
An error occurs if
does not exist,
creates it and copies the subtree rooted at
cannot merge subtrees.
Usually normal files and directories are copied. Character
special devices, block special devices, network special files,
named pipes, symbolic links, and sockets are copied, if the
user has access to the
otherwise, a warning
is printed stating that the file cannot be created,
and the file is skipped.
should not reside within
have a cyclic directory structure, since in both cases
attempts to copy an infinite amount of data.
will exit with error if multiple sources are being copied to
a non-existing directory.
(recursive subtree copy) The
option is identical to the
options, in addition to regular files and directories,
also copies FIFOs, character and block device files and symbolic links.
superusers can copy device files. All other
users get an error.
Symbolic links are copied so the target points to the same
location that the source did.
Warning: While copying a directory tree that has device special files,
otherwise, an infinite amount of data is read from the device
special file and is duplicated as a special file in the destination
directory occupying large file system space.
to traverse the symbolic link specified as an operand and copy
it to the destination.
to traverse the symbolic link specified as an operand or any symbolic links
encountered during traversal of a file hierarchy, and copy it to the
to copy the symbolic link specified as an operand and any symbolic links
encountered during traversal of a file hierarchy. This option will not
follow any symbolic links.
- -e extarg
Specifies the handling of any extent attributes of the file[s] to be
takes one of the following values.
Issues a warning message if extent attributes cannot be copied,
but copies the file anyway.
Does not copy the extent attributes.
Fails to copy the file if the extent attribute can not be copied.
Extent attributes can not be copied if the files are being copied to a
file system which does not support extent attributes or if that file system
has a different block size than the original.
is not specified, the default value for
Specifies "safe" mode. This minimizes the impact of
on the performance of the system by opening the target file using the
flag. This is
when the total size of the copy (not of a single file)
is a significant portion of the size of system buffer
cache. Usage of this option increases copy time.
Specifying more than one of the mutually-exclusive options
will not be considered an error.
The last option specified will determine the behavior of the utility.
Access Control Lists (ACLs)
is a new file, or if a new file is created in
it inherits the access control list of the original
etc., altered to reflect any difference in ownership
between the two files (see
In JFS file systems, new files created by
do not inherit their parent directory's default ACL entries (if any),
but instead retain the ACLs of the files being copied. When copying
files from a JFS file system to an HFS file system or vice versa,
optional ACL entries are lost.
For information about the UNIX standard environment, see
determines the interpretation of text as single and/or
determine the local language equivalent
of y (for yes/no queries).
determines the language in which messages are displayed.
is not specified in the environment or is set to
the empty string, the value of
is used as a default for each
unspecified or empty variable. If
is not specified or is set to the empty string,
a default of "C" (see
is used instead of
If any internationalization variable contains an invalid setting,
behaves as if all internationalization variables are set to "C".
International Code Set Support
Single- and multi-byte character code sets are supported.
The following command moves the directory
and its contents to a new location
in the file system.
creates the new directory, the destination directory
should not already exist.
cp -r sourcedir targetdir && rm -rf sourcedir
option copies the subtree (files and subdirectories) in directory
The double ampersand
causes a conditional action.
If the operation on the left side of the
is successful, the right side is executed (and removes the old directory).
If the operation on the left of the
is not successful, the old directory is not removed.
This example is equivalent to:
To copy all files and directory subtrees
in the current directory to an existing
To copy all files and directory subtrees in
cp -r sourcedir/* targetdir
Note that directory pathnames can precede both
To create a zero-length file, use any of the following:
cat /dev/null >file
cp /dev/null file
Access control lists of networked files are summarized (as returned in
but not copied to the new file.
on such files, a
is not printed after the mode value
when asking for permission to overwrite a file.
was developed by AT&T, the University of California, Berkeley,
cp: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2