The cp command is used to copy data from one location to another option in Linux and its other Linux distributions. The cp command is used in Linux to copy one or more files, directories, images, etc. from one location to another. With this command, you can create the exact image of an already created file in the Linux system.
Syntax:
cp [OPTION] Source Destination cp [OPTION] Source Directory cp [OPTION] Source-1 Source-2 Source-3 Source-n Directory
The first and second syntax is used to copy a file and directory from one location to another and the third syntax is used to copy more than one file and directory to another location.
To copy files and directories with the cp command in Linux, you must have two main locations, in which the first is Source (which file you want to copy) and the second is Destination (the place where you want to copy the file).
Copy Two file names: If you want to copy a file from one place to another then the cp command will create the exact image of your source file in the destination location. If the same filename already exists in the destination then the cp command will overwrite the data on it without any confirmation, so make sure before copying the file to the destination.
cp Source_file Destination_file
# cp data_file data
As you can look in the screen below that cp command we have copied the file of data_file1 to the data directory and used the ls command to confirm that the file is successfully copied, Or not. similarly, you can copy your source file to the selected destination.

Copy More than One file: If you want to copy more than one file to the destination location by cp command, then for this you have to write the name of all the files with a single space after the command. If the file to be copied to the source location does not exist in the destination, the source image file will be created, and if the file is available, it will be overwritten.
To copy a file with the cp command, the destination location must be a directory because cp does not create a directory at the time of file copying. Linux system will show an error if the destination directory does not exist.
cp Src_file1 Src_file2 Src_file3 Dest_location
For example, we have a file named file1 file2 file3 file4 in the source and want to copy it to the data destination directory for this we type the all the names of the file to be copied from the source with a single space after the cp command and then type the destination In this example, our destination is the data directory, you can take anything according to you.
#cp file1 file2 file3 file4 file5 data1

Copy Directory Now we have learned how to copy the files present in a directory from one place to another, but if there are many files in a directory, then you can copy the directory. To copy a directory from the source, you have to use the -R option after the cp command.
R indicates recursive which means it will copy all the files present in the directory to the destination location. If the directory does not exist in the destination, then the cp command will create a new directory and copy all the files on it, and if the directory is available in the destination, then the cp command creates a subdirectory and copies all the destination data.
cp -R Src_directory Dest_directory

-b(backup): If you want to copy the source directory to the destination with a different name, such as to create a backup directory or for other tasks, then you have to use -b with the cp command.
$ cp -b file1 /root/Desktop/file_bkp

Copying using * wildcard: With the wild card option, you can copy any file and directory at once, as if you have to copy many files to the destination, then you will copy the files one by one or use the large command with argument but with * wild card you can do this very easily.
$ cp-r * /root/Desktop

-i (interactive): i stand for Interactive copying. If you want to take confirmation from the user before overwriting on the destination File, then for this you should use the -i option.
$ cp -i file1 /root/Desktop

-f(force): This option is used in the cp command to force-copy files and directories to the destination. For this you need -f . have to use
$ cp -f file1 /root/Desktop
Verbose option: When we don’t use the -v option to copy files and directories, the process of copying files and directories works in the back end, and if you want to see the copying process you have to use the –v option.
$ cp -rv data2 /root/Desktop

copy file and directory from other sources:
If the file or directory you want to copy is not in your current location and you want to copy the file or directory from another source, then you have to use dot (.). For example, if my project is in the /root directory and I am working on it and I want to copy files from the desktop then this is the best option.

Related Article: vim commands in Linux with examples and our other blog simiservice.com
- What is a Blog? Uses, History, Types, and How It Works - 26 March 2025
- How to Choose Right Pen Drive: Storage, Speed, Security & More - 26 March 2025
- Difference Between Linux and Unix : Major Differences - 26 March 2025