DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

cp(C)


cp -- copy files

Syntax

cp [ -fip ] source_file target_file

cp [ -fip ] source_file1 source_file2 ... target

cp -R [ -fip ] source_file1 source_file2 ... target

cp -r [ -fip ] source_file1 source_file2 ... target

Description

cp copies files from a source to a destination.

In the first form, when source_file and target_file are not directories, the contents of source_file are copied to target_file.

In the second form, where target is a directory, cp copies each named source file to a destination of the same name within the directory target.

The third and fourth forms are described with the options below.

cp recognizes the following options:


-f
If the destination file exists but is not writeable, it is unlinked before copying is performed. Any hard links to the file are lost. (This option forces cp to overwrite existing files.)

-i
Before attempting to copy to an existing file, cp prompts for confirmation. The copy operation is not performed unless the user types an affirmative.

-p
When copying, cp tries to transfer the following characteristics from each source file to the corresponding destination file:

-r
Copies file hierarchies recursively.

-R
Copies file hierarchies recursively. Also permits copying of device nodes and named pipes. (The copy of a device node or pipe is assigned the file permissions of the source file, subject to the user's UMASK setting, unless the -p option is applied).

Examples

To copy /etc/passwd to passwd in the current directory:

cp /etc/passwd passwd

To copy all the files in directory mydir to backupdir, overwriting any files which exist there and have the same name:

cp -f mydir/*  backupdir

To copy all the files in mydir and all its subdirectories to backupdir:

cp -R mydir backupdir

To copy input from the terminal /dev/tty to inputfile until the user types <Ctrl>d:

cp -r /dev/tty inputfile

Limitations

It is not possible to copy a directory to a file.

See also

copy(C), chmod(S), cpio(C), ln(C), mv(C), rm(C)

Standards conformance

cp is conformant with:

ISO/IEC DIS 9945-2:1992, Information technology - Portable Operating System Interface (POSIX) - Part 2: Shell and Utilities (IEEE Std 1003.2-1992);
AT&T SVID Issue 2;
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992.


© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003