commands

cp — copy files and directories

Copies data; an existing destination directory usually receives the source basename. Existing destination files can be replaced. Review scope and symlinks. -a requests archival preservation, which is limited by filesystem and privileges. Examples assume a fresh chapter files lab.

Formal Syntax & Structure

linux syntaxlinux
cp [OPTION]... SOURCE DEST

Parameters & Attributes

NameTypeDescription
-ioptionPrompt before overwrite
-RoptionCopy directories recursively
-aoptionArchive mode
SOURCEoperandObject to copy
DESToperandDestination path

Return Value

filesystem change and exit status

GNU cp returns 0 on success and nonzero on failure. Declining an interactive overwrite left the destination unchanged and returned 1 in the tested GNU version; check destination bytes and required metadata.

Working Example

Example Snippetlinux
cp -i notes/hello.txt archive/hello.txt
Linux Reference