cp command in Linux/Unix

cp command is used for copying files or directories from one location to another location. The copied files or directories are entirely independent of the original files or directories.

Syntax of cp command

cp [option] Source Destination
  • Source can be one or more than one files or  directories as arguments
  • Destination can be a single file or directory.

Uses of cp command with example

Copying file to another file

cp command can be used to copy files from one location (source) to another location (destination). If doesn’t exist, the cp command creates it.

cp source_file_name destination_file_name

cp cpmmand in linux

Copying file to another directory

cp command can be used to copy files from one location (source) to another location (destination). The destination directory must exist. If the destination directory doesn’t exist, the cp command does not create it.

cp source_file_name destination_directory_name

copy file to another directory

Copying directory to another directory

cp command can be used to copy one or more directories to another directory. To copy from one directory to another directory use the following command.

cp -r source_directory_name destination_directory_name

copy one directory to other directory

Sharing is Caring
Scroll to Top