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 DESTParameters & Attributes
| Name | Type | Description |
|---|---|---|
| -i | option | Prompt before overwrite |
| -R | option | Copy directories recursively |
| -a | option | Archive mode |
| SOURCE | operand | Object to copy |
| DEST | operand | Destination 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