HP-UX Reference (11i v1 05/09) - 1 User Commands A-M (vol 1)
c
cp(1) cp(1)
NAME
cp - copy files and directory subtrees
SYNOPSIS
cp [-f-i][-p
][-S][-e extarg ] file1 new_file
cp [-f-i][
-p][-S][-e extarg ] file1 [file2 ...] dest_directory
cp [-f-i][-p
][-S][-R-r][-e extarg ] directory1 [directory2 ... ] dest_directory
DESCRIPTION
cp copies:
• file1 to new or existing new_file,
• file1 to existing dest_directory,
• file1, file2, ... 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 file1 and new_file 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 destina-
tion must be a directory. When copying a single file to a new file, if new_file exists, its contents are des-
troyed.
If the access permissions of the destination dest_directory or existing destination file new_file forbid writing,
cp aborts and produces an error message ‘‘cannot create file’’.
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 file to another file or files to a directory.
If new_file is a link to an existing file with other links,
cp overwrites the existing file and retains all links.
If copying a file to an existing file,
cp 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,
cp creates a new file with the
same file permission bits as file1, modified by the file creation mask of the user if the
-p option was not
specified, and then bitwise inclusively ORed with S_IRWXU. The owner and group of the new file or files
are those of the user. The last modification time of new_file (and last access time, if new_file did not exist)
and the last access time of the source file1 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 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. If the -i
(interactive) and -f
(forced-copy) options are both specified, the -i option is ignored.
-f Force existing destination pathnames to be removed before copying, without prompting for
confirmation. 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.
-p (preserve permissions) Causes cp to preserve in the copy as many of the modification time, access
time, file 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.Ifdest_directory exists, it must be a directory, in which case
cp creates a direc-
tory within dest_directory with the same name as file1 and copies the subtree rooted at file1 to
dest_directory/file1. An error occurs if dest_directory/file1 already exists. If dest_directory does
not exist,
cp creates it and copies the subtree rooted at file1 to dest_directory. Note that cp -r
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 file; otherwise, a warning is printed stating that the file cannot be created, and the file 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 infinite amount of data.
Section 1−−114 Hewlett-Packard Company − 1 − HP-UX 11i Version 1: September 2005