E-mail : support@tech2now.in

cp command with examples

Linux Linux command ls pwd cp mv more grep tail

The cp command is used to copy files and directories from source to destination. It allows you to duplicate files and directories, preserve their permissions and attributes, and create backups.

Examples

Copy a file from source location to destination location. In this commamd copies the file file.txt from source location to the destination location /app/destination/

$cp file.txt /app/destination/

Copy multiple files from source directory to destination directory.

$cp file1.txt file2.txt /app/destination/

Copy a directory and its contents from source location to destination location

$cp -r directory/ /app/destination/

Preserve file attributes and permissions of the file and folder during the copy from source to destination.

$cp -a file.txt /app/destination/

Prompt for confirmation before overwriting an existing file between source location and destination location

$cp -i file.txt /app/destination/