Forever & AlwaysLINUX COMMAND ATLAS

LINUX COMMAND ATLAS · COMMAND GUIDE

Linux cp command

Copy files. Add -r when copying a directory and its contents.

GNU Coreutils

Syntax

Command form
cp [OPTION]... SOURCE... DESTINATION

Common options

7 options
OptionWhat it does
-a, --archivePreserve attributes and copy recursively; equivalent to -dR --preserve=all.
-r, -R, --recursiveCopy directories recursively.
-i, --interactivePrompt before overwriting a destination.
-n, --no-clobberDo not overwrite an existing destination.
-u, --updateCopy when the source is newer or destination is missing.
-p, --preserve=mode,ownership,timestampsPreserve selected file attributes.
-v, --verboseExplain what is being copied.

Usage examples

3 examples

Copy files. Add -r when copying a directory and its contents.

cp -r ./assets ./backup/assets

Copy a file and ask before overwriting.

cp -i report.txt ./archive/

Copy a directory tree while preserving attributes.

cp -a project/ backup/project/

Notes

Use -i or -n when overwriting could lose data. GNU and BSD cp have some option differences.