cp

cp [options] file1 file2
cp [options] files directory

Copy file1 to file2, or copy one or more files to the same names under directory. If the destination is an existing file, the file is overwritten; if the destination is an existing directory, the file is copied into the directory (the directory is not overwritten). If one of the inputs is a directory, use the -r option.

Options

-i

Prompt for confirmation (y for yes) before overwriting an existing file.

-p

Preserve the modification time and permission modes for the copied file. (Normally cp supplies the permissions of the invoking user.)

-r

Recursively copy a directory, its files, and its subdirectories to a destination directory, duplicating the tree structure. (This option is used with the second command-line format when at least one of the source file arguments is a directory.) Bear in mind that both symbolic and hard links are copied as real files; the linking structure of the original tree is not preserved.

Example

Copy two files to their parent directory (keep the same names):

cp outline memo ..


Previous: Reference: compressUNIX in a Nutshell: System V EditionNext: Reference: cpio
Reference: compressBook IndexReference: cpio

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System