$linuxjunkies
>

cp(1)

Copy files and directories.

UbuntuDebianFedoraArch

Synopsis

cp [OPTION]... SOURCE... DESTINATION

Description

Copy SOURCE file(s) to DESTINATION. If multiple sources are given, DESTINATION must be a directory. By default, cp does not copy directories recursively; use -r or -R to do so.

When copying, ownership and permissions may change depending on whether -p is used and the destination location. Symbolic links are followed by default unless -P is specified.

Common options

FlagWhat it does
-r, -Rcopy directories recursively
-ppreserve mode, ownership, and timestamps
-aarchive mode; same as -dR --preserve=all
-fforce overwrite without prompting
-iprompt before overwriting existing files
-vprint names of copied files
-dsame as --no-dereference --preserve=links
-Pnever follow symbolic links in SOURCE
--updatecopy only when source is newer than destination
-ndo not overwrite existing files

Examples

copy a single file in the current directory

cp file.txt file_backup.txt

copy file to a specific directory

cp file.txt /home/user/Documents/

copy entire directory and its contents recursively

cp -r /home/user/mydir /home/user/mydir_backup

copy while preserving permissions and timestamps

cp -p important.conf important.conf.bak

copy all .log files verbosely to archive directory

cp -v *.log /var/log/archive/

copy with confirmation prompt if destination exists

cp -i file.txt /tmp/file.txt

archive-mode copy preserving all attributes and symlinks

cp -a /home/user/project /backup/project

copy only if source is newer than destination

cp --update old.txt new.txt

Related commands