NAME
cp - Copies files
SYNOPSIS
cp [-fhip] [--] source_file destination_file
cp [-fhip] [--] source_file ... destination_directory
cp [-fhip] [-R | -r] [--] [source_file | source_directory]
... destination_directory
The cp 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.
FLAGS
-f Overrides the i option; cp does not prompt you when an
existing file is to be overwritten. (If both -f and -i
are specified on the command line for example, because
an alias includes one of them whichever appears last
overrides the other.)
-h Forces cp to follow symbolic links; useful with with the
-R option, which does not follow symbolic links by
default.
-i Prompts you with the name of the file whenever the copy
causes an old file to be overwritten. An answer begin-
ning with y, or the locale's equivalent of y, causes cp
to continue. Any other answer prevents it from
overwriting the file. (If both -f and -i are specified
on the command line for example, because an alias
includes one of them whichever appears last overrides
the other.)
-p 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 -D, 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 permis-
sions.
-R When the source is a directory, copies the directory and
the entire subtree connected at that point. Special
file types, such as symbolic links and block and charac-
ter devices, are recreated instead of being copied.
Created directories have the same mode as the
corresponding source directory, unmodified by the
process's file mode creation mask (umask).
-r Identical to -R except that special files are not
treated differently from regular files (follows symbolic
links). The -R option is preferred.
-- Indicates that the arguments following this flag are to
be interpreted as filenames. This null flag allows the
specification of filenames that start with a minus.
DESCRIPTION
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 source file
and the destination file are owned by the same user and
group.
Appropriate permissions are always required for file crea-
tion or overwriting.
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).
EXAMPLES
1. To copy one file to another, enter:
cp file1 file2
If file2 exists (and is writable), it is replaced by
file1.
2. To copy files to a directory, enter:
cp file1 file2 dir1
dir1 must exist.
3. To copy all files in a directory and preserve their
modification times, enter:
cp -p dir1/* dir2
4. To copy a directory tree to another directory, enter:
cp -R dir1 dir2
The dir1 tree is created in dir2.
NOTES
1. Do not give the destination the same name as one of the
source files.
2. If you specify a directory as the destination, the
directory must already exist.
3. If you are using the -r option to copy the contents of
one directory to another, and source_directory contains
subdirectories that do not exist in
destination_directory, the subdirectories will be
created.
EXIT VALUES
The cp command returns 0 (zero) upon successful completion
and greater than 0 (zero) if an error occurs.
RELATED INFORMATION
Commands: cpio(1), link(1)/unlink(1), ln(1), mv(1).
Acknowledgement and Disclaimer