Linux Commands | File Management | cp Copy Files/Directories

cp

cp is a command used to copy files or directories.

cp is short for “copy”.

cp Syntax

cp (options) [source file path/name (multiple allowed)] [destination path/name]

cp Options

Option Description
-r Copies all subdirectories and files under the target path.
-p Preserves the owner, group, permissions, and timestamps of the source file.

If a file with the same name already exists at the destination, a prompt appears asking whether to overwrite it.

cp Examples

Copy multiple files to the /backup directory

cp /etc/inittab /etc/passwd /boot/grub/grub.conf /backup

Copy the /etc/skel directory to the /backup directory

cp -r /etc/skel /backup

Copy while preserving source file permissions

cp -p /etc/passwd /backup

Copy the /etc/inittab file to /backup with the name init

cp /etc/inittab /backup/init