The cp command in Linux is used to copy files and directories by using the command line. This command also allows you to move multiple files and folders at once while preserving their backup and attribute information. So the cp command is very useful for Linux users.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Linux System configuration queries.
In this context, we shall look into how to copy multiple files using the cp command in Linux.
It is given below:
$ cp [filename] [filename2]
You must provide a filename and destination directory to do this.
The syntax is:
$ cp [filename] [filename1] [folder name]/
To copy the directory we must use the -r option:
$ cp -r foldername/ foldername 1
The syntax is:
$ cp -r foldername foldername 1 foldername 2
The destination folder will be at the end.
Let's use the -b option to backup when copying files:
$ cp -b [filename] [filename2]
For example, we will backup the hello.pl file:
$ cp -b hello.pl hellobk.pl
This article covers how to copy multiple files using the cp command in Linux. In fact, cp is the command entered in a Unix and Linux shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name.