Skip to content

cp

12 commands

Copies files and directories, preserving attributes when asked.

  • files

Install cp

sudo apt install coreutils

Basics6

cp <src> <dest>

Copies a file. Overwrites the destination without asking.

Link
cp <file1> <file2> <dir>/

Copies several files into a directory.

Link
cp -r <dir> <dest>

Copies a directory recursively.

Link
cp -i <src> <dest>

Asks before overwriting.

cp -n <src> <dest>

Never overwrites existing files.

Link
cp -v <src> <dest>

Prints each file as it is copied.

Link

Preserving attributes4

cp -p <src> <dest>

Keeps mode, ownership and timestamps.

Link
cp -a <src> <dest>

Archive mode: recursive, preserves everything including symlinks. Best for backups.

Link
cp -u <src> <dest>

Copies only when the source is newer or the destination is missing.

Link
cp --backup=numbered <src> <dest>

Keeps numbered backups of anything it overwrites (GNU).

Link