cp - Copies files
cp [-fhip] [--] source_file destination_file
cp [-fhip] [--] source_file... destination_directory
cp [-fhip] [-r|-R] [--] [source_file|source_directory]... destination_directory
command copies a source file or the files
in a source directory to a destination file or directory. If your source and
destination are directories, the source is copied to the destination and created
with the same name.
Interfaces documented on this reference page conform to industry standards as follows:
cp: XPG4, XPG4-UNIX
Refer to the
reference page for more information
about industry standards and associated tags.
command does not prompt
you when an existing file is to be overwritten. (If both
are specified on the command line--for example,
because an alias includes one of them--whichever appears last overrides
[Compaq] Together with the
same as the
Prompts you with the name of the file whenever the copy would
cause an existing file to be overwritten. An answer beginning with
y, or the locale's equivalent of
to continue. Any other answer prevents it from overwriting the
Preserves for the copy the modification time, access time,
file mode, user ID, and group ID of the original, as allowed by permissions.
If the user ID and group ID cannot be preserved, no error message is displayed
and the exit value is not altered. If the original 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. [Compaq] Preserves
the extended file attributes (property list), including the access control
list (ACL) if any.
When the source is a directory, copies the directory and the
entire subtree connected at that point. Special file types, such as symbolic
links, named pipes (FIFOs), and block and character devices, are opened and
their contents are copied to regular files having the same name. (This may
be desired for links but is probably not desired for disk, tape, or network
devices.) For example, if
is a symbolic link
is not a symbolic link to file
but is a copy of it.
-r, when the source is a directory,
copies the directory and the entire subtree connected at that point. However,
destination_files are created with the same file types as
source_files, for instance symbolic links, named pipes (FIFOs),
or block or character devices. As an example, if
is a symbolic link to file
is copied to
will also be a symbolic link
is a FIFO, the file permission bits of
are set to those of
modified by the
file creation mask of the user if the
option is not used.
Indicates that the arguments following this option are to
be interpreted as file names. This null option allows the specification of
file names that start with a minus.
If a destination file already exists, its contents are overwritten if permissions allow, but cp does not change its mode, user ID, or group ID. However, if the file is not being copied by the root user, writing the file may clear the set-user-ID or set-group-ID permission bits.
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 -p option is used.
Appropriate permissions are always required for file creation or overwriting.
[Compaq] You can also copy special device files. If the file is a named pipe, the data in the pipe is copied into a regular file. If the file is a device, the file is read until the end of file, and that data is copied into a regular file.
The LC_MESSAGES variable determines the locale's equivalent of y or n (for yes/no queries).
is a directory, the following
If neither the
was specified, an error message is displayed and
is not copied.
If the target specified exists and is a file, not a directory,
an error message is displayed and
If the target does not exist and the
is specified, the permission bits of the target directory are set equal to
the source directory bitwise inclusively ORed with
(0700 octal). This means the newly created directory will always allow the
owner read, write and execute permission.
If the target does not exist and the
is not specified, the permission bits of the target directory are set equal
to the source directory bits, modified by the file creation mask of the user
(shuts off the corresponding permission bits specified in the umask). The
resulting permission bits are then ORed with
octal) which gives the owner read, write and execute permission.
If the target does not exist and cannot be created, an error
message is displayed and
is not copied.
Do not give the destination the same name as one of the source
If you specify a directory as the destination, the directory
must already exist.
If you are using the
option to copy the
contents of one directory to another, and
contains subdirectories that do not exist in
destination_directory, the subdirectories are created.
The following exit values are returned:
An error occurred.
To copy one file to another, enter: cp file1 file2
The following environment variables affect the execution of
Provides a default value for the internationalization variables
that are unset or null. If
is unset or null, the corresponding value from the default locale is used.
If any of the internationalization variables contain an invalid setting, the
utility behaves as if none of the variables had been defined.
If set to a non-empty string value, overrides the values of
all the other internationalization variables.
Determines the locale for the interpretation of sequences
of bytes of text data as characters (for example, single-byte as opposed to
multibyte characters in arguments).
Determines the locale for the format and contents of diagnostic
messages written to standard error.
Determines the location of message catalogues for the processing
Commands: cpio(1), find(1), link(1), ln(1), mv(1), pax(1), tar(1), umask(1)
Files: proplist(4), acl(4)