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.
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:
Beware of a recursive copy like this:
example% cp -r ~/src ~/src/bkup
which keeps copying files until it fills the entire file system.
Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97