up | Inhaltsverzeichniss | Kommentar

Manual page for CP(1)

cp - copy files

SYNOPSIS

cp [ -ip ] filename1 filename2
cp -rR [ -ip ] directory1 directory2
cp [ -iprR ] filename ... directory

DESCRIPTION

cp copies the contents of filename1 onto filename2. The mode and owner of filename2 are preserved if it already existed; the mode of the source file is used otherwise. If filename1 is a symbolic link, or a duplicate hard link, the contents of the file that the link refers to are copied; links are not preserved.

In the second form, cp recursively copies directory1, along with its contents and subdirectories, to directory2. If directory2 does not exist, cp creates it and duplicates the files and subdirectories of directory1 within it. If directory2 does exist, cp makes a copy of the directory1 directory within directory2 (as a subdirectory), along with its files and subdirectories.

In the third form, each filename is copied to the indicated directory; the basename of the copy corresponds to that of the original. The destination directory must already exist for the copy to succeed.

cp refuses to copy a file onto itself.

OPTIONS

-i
Interactive. Prompt for confirmation whenever the copy would overwrite an existing file. A y in answer confirms that the copy should proceed. Any other answer prevents cp from overwriting the file.
-p
Preserve. Duplicate not only the contents of the original file or directory, but also the modification time and permission modes.
-r
-R
Recursive. If any of the source files are directories, copy the directory along with its files (including any subdirectories and their files); the destination must be a directory.

EXAMPLES

To copy a file:
example% cp goodies goodies.old
example% ls goodies*
goodies goodies.old

To copy a directory, first to a new, and then to an existing destination directory:

example% ls ~/bkup
/usr/example/fred/bkup not found
example% cp -r ~/src ~/bkup
example% ls -R ~/bkup
x.c y.c z.sh
example% cp -r ~/src ~/bkup
example% ls -R ~/bkup
src x.c y.c z.sh
src:
x.c y.c z.sh

To copy a list of files to a destination directory:

example% cp ~/src/* /tmp

SEE ALSO

cat.1v ln.1v mv.1 pr.1v rcp.1c tar.1

WARNINGS

Beware of a recursive copy like this:

example% cp -r ~/src ~/src/bkup

which keeps copying files until it fills the entire file system.

BUGS

cp copies the contents of files pointed to by symbolic links. It does not copy the symbolic link itself. This can lead to inconsistencies when directory hierarchies are replicated. Filenames that were linked in the original hierarchy are no longer linked in the replica. This is also true for files with multiple hard links. See ln.1v for details about symbolic links and hard links. You can preserve links in replicated hierarchies by using tar.1 to copy them.


index | Inhaltsverzeichniss | Kommentar

Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97