How to Copy Multiple Specific Files From One Folder to Another?

In Linux, copying single/multiple files from one place to another is usually performed on daily basis.  The copying process keeps the backup of the important files that the user does not want to lose in any way. In case the original files are lost then the copied files will be saved as a backup. In addition, the copying process can also be used for archiving files/folders due to less storage on a disk.

Considering this in view, this post shows possible aspects to copy multiple files from one folder to another in Linux:

Method 1: Use “cp” Command

The “cp” refers to the built-in “copy” command to copy files and directories from one location to another. It comes with a variety of supported flags that performs the tasks according to the user’s requirements.

Syntax:

The basic syntax to copy multiple files is typed below:

$ cp [path/of/file1][path/of/file2].....[path/of/fileN] [Destination path]

The syntax holds the following parameters.

  • cp: Represents the main “copy” command.
  • path/of/file: Shows the absolute path of the multiple specific files.
  • Destination path: Specify the destination place of the copied files.

Example 1: Copying Multiple FIles

Run the “cp” command to copy the multiple specific files having different extensions such as “.txt”, “.pdf”, “.jpeg” and so on into the targeted directory:

$ cp /home/itslinuxfoss/Documents/file1.txt /home/itslinuxfoss/Extra/file2.pdf /home/itslinuxfoss/New/images.jpeg /home/itslinuxfoss/Downloads/

The specified “.txt”, “.pdf”, “.jpeg” files have been copied into “Downloads” directory.

Example 2: Copy Multiple Files Having Same Extension 

Execute the cp command without passing any argument to copy the five “.txt” files from the “Documents” directory to the “Pictures” directory in this way:

$ cp /home/itslinuxfoss/Documents/{file1,file2,file3,file4,file5}.txt /home/itslinuxfoss/Pictures/

All the five files have been copied from “Documents” to “Pictures” directory.

Another way to do the same process is by using the series pattern of the “cp” command.

To do so, specify the file series, i.e., “File{A…K}” having the same extensions and prefixes as shown below:

$ cp /home/itslinuxfoss/File{A..K}.pdf /home/itslinuxfoss/Sample/

It is confirmed that “File{A..Z}” series has been copied from “home” to “Sample” directory.

Example 3: Ask Permission to Copy Multiple Files 

The “cp” command offers the lowercase “-i(permission)” flag before copying files/ directories for the user’s permission to overwrite the existing same-name file.

In this example, four copied “.mp3” files of the “Extra” directory are overwritten to the four existing files of the “Sample” directory by asking the logged-in user for confirmation:

$ cp -i /home/itslinuxfoss/Downloads/Audio{1..4}.mp3 /home/itslinuxfoss/Extra/

The above operation performed successfully.

Example 4: Create Backup and Copy Multiple Files

It is recommended to create a backup of the copied files by using the “-b(backup)” flag of the “cp” command line tool:

In the below command, five files of “.jpg” format have been copied from “Pictures” to “snap” directory and generated their backup files:

$ cp -b /home/itslinuxfoss/Pictures/{imga1,imgb2,imgc3,imgd4,imge5}.jpg /home/itslinuxfoss/snap/

The “~(tild)” sign indicates the backup files. 

Example 5: Use Wildcard to Copy Multiple Files

Instead of typing file names having the same extensions in the “cp” command, use the “*(wildcard)” in this way:

$ cp  /home/itslinuxfoss/*.txt /home/itslinuxfoss/New/

All the “.txt” files of “home” directory has been copied from “New” directory.

Method 2: Use the “rsync” Command

The “rsync” command allows the users to copy multiple files from a local to the remote system. In this method, “rsync” is used to copy multiple specific files from one folder to another within the local system.

Syntax:

The generalized syntax of the “rsync” command to copy multiple files is written below:

$ rsync [path/of/file1][path/of/file2].....[pathN/of/fileN][Destination Path ]

First, the path of the source files is given, and then the destination. 

Example: 

The practical implementation of the above “rsync” syntax is shown below:

$ rsync /home/itslinuxfoss/notes/File{1..6}.pdf /home/itslinuxfoss/Documents

The specified “.pdf” files have been copied from the “New” directory.

Method 3: Use the “Copy” Option | GUI Method

GUI of the Linux system (where applicable) offers an easy and convenient way to copy multiple files from source to destination. Let’s see how it works: 

Step 1: Select Multiple Files 

Use the mouse/keyboard to select multiple files. Here, all files having the “.jpg” extension (the method id applicable for selecting files having multiple extensions) are selected:

Step 2: Copy Multiple Files

Right-click on the selected files and hit the “copy” option from the drop-down menu:

The user can also use the “Ctrl+C” shortcut key to copy files.

Step 3: Paste Multiple Files 

Navigate to the destination folder and right-click from the mouse. Select the “Paste” option to paste all copied files there”:

Once clicked on the “Paste” option, the files will be copied to the desired place:

Conclusion

Linux offers the pre-installed “cp” and “rsync” command line tools to copy multiple specific files from source to destination. The user can also perform this task using “copy” option or “Ctrl+C” shortcut key via the graphical user interface. This guide has listed down both CLI and GUI methods to copy multiple specific files from one folder to another.