cp.1 (2012 03)
c
cp(1) cp(1)
NAME
cp - copy files and directory subtrees
SYNOPSIS
cp [-f-i][-p
][-S][-A][-e extarg ] file1 new_file
cp [-f-i][-p
][-S][-A][-e extarg ] file1 [file2 ... ] dest_directory
cp [-f-i][
-p][-S][-R-r][-A][-e extarg ] directory1 [ directory2 ... ] dest_directory
cp -R-r [-H-L
-P][-f-i][-p][-S][-A
][-e extarg ] file1 directory1 [file2 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 destina-
tion is a directory, one or more files are copied into that directory. If two or more files are copied, the des-
tination must be a directory. When copying a single file to a new file, if new_file exists, its contents are
destroyed.
If the access permissions of the destination dest_directory or existing destination file new_file forbid writ-
ing,
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) Causes 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.
-f (force copy) Forces 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.
When the
UNIX95/UNIX2003 flag is set and if the destination file exists and the user has write
permission on the destination file, then the destination file is not removed.
-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) Causes 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
HP-UX 11i Version 3: March 2012 − 1 − Hewlett-Packard Company 1