← All languages
$_
Bash command of the day

cp

Copy files and directories.

Description

The cp command copies files and directories from a source to a destination. By default, it copies a single file to a new location or overwrites an existing file.

When copying directories, the -r (recursive) option is required. cp preserves the file structure within the source directory and recreates it at the destination.

cp supports options for preserving file attributes, creating backups, interactive prompting before overwriting, and following or not following symbolic links.

Arguments

NameDescriptionOptional
source The file or directory to copy. No
dest The destination file or directory. No
-r Copy directories recursively. Yes
-i Prompt before overwriting an existing file. Yes
-p Preserve file mode, ownership, and timestamps. Yes

Example

cp file.txt backup.txt
cp -r src/ dest/
cp -i important.conf /etc/