How to Copy Multiple Files Linux?

Copying files is the primary operation of any operating system. Like other operating systems, Linux offers effective command-line support to copy multiple files and put them in a specific location. Apart from the command line method, the GUI (where applicable) can also copy multiple files.

This post will enlist the possible command line and GUI methods to copy multiple files in Linux. The outline of the post is as follows:

Let’s start with the command line method first.

Method 1: How to Copy Multiple Files Linux via Command Line?

There are two most used commands to copy multiple files in Linux using the command line interface. One is the “cp” command, and the second is the “rsync” command. Let’s head over to the “cp” command first:

Method 1.1: Using the “cp” Command

The “cp” command allows the users to copy single/multiple files into the same or another directory. The basic syntax of the “cp” command to copy multiple files is written below:

Syntax:

$ cp [filename 1] [filename 2] [Directory]/

The above syntax contains the main keyword “cp”, and the square brackets show the desired files that need to be copied and the target directory.

The “cp” command also provides a list of supported options that can be obtained by executing the below “help” command.

$ cp --help

To check more options, scroll down the “help” page of the “cp” command.

Example 1: Copy Multiple Files

In this example, the “Documents” directory contains five files, as shown in the screenshot via the “ls -l” command. The “ls -l” command lists down the content of the file/directory:

$ ls -l

Type the “cp” command with the first four files’ names and the target directory “Notes” as written below:

$ cp File1.txt File2.txt File3.txt File4.txt Notes/

The first four files of the “Documents” directory have been copied to the “Notes” directory. Run the below “ls -l” command to verify the results:

$ ls -l Notes

Example 2: Create Backup Before Copy Multiple Files (Recommended)

The “cp” command offers the “-b” flag to create the backup of files that are going to be copied. Suppose the “File5.txt” and the “File6.txt” is placed in the “Dir” directory. Run the below “cp” command with the “-b” argument to create the backup of these files:

$ cp -b File6.txt File7.txt

Run the “ls -l” command to check the created backup files:

$ ls -l

The “~” after “File6” and “File7” identifies the backup files.

Example 3: Ask For Confirmation to Copy Multiple Files

The “cp” command allows the user to ask for confirmation before copying multiple files into a directory. For this purpose, use the “-i” argument of the “cp” command. If the target file is already created, the “i” flag asks to overwrite that file.

Enter the following command in the terminal to allow the “cp” command for copying the mentioned multiple files:

$ cp -i NewFile1.txt NewFile2.txt

 Type “y(yes)” to overwrite the “NewFile2.txt”.

Method 1.2: Using the “rsync” Command

The “rsync” command allows the users to copy multiple files from one source place to the destination place in the local system. The user can also keep syncing the files between different directories. The syntax of the “sync” command is written below:

Syntax:

$ rsync [path file1][path file2].............[path fileN][Destination Path ]

The “rsync” syntax shows the following components:

  • rysync: Identifies the “rysync” command.
  • [path file1]…[path fileN]: Denotes the desired files with the absolute path, i.e./home/documents/file.txt.
  • [Destination Path]: Target where copied files need to be placed.

Copy Multiple Files Using rsync Command

Suppose the directory “notes” contains three files displayed by the “ls -l” command:

$ ls -l notes

Use the below-mentioned “rsync” command to copy these multiple files in the target “Documents” directory:

$ rsync /home/itslinuxfoss/notes/File1.txt /home/itslinuxfoss/notes/File2.txt /home/itslinuxfoss/notes/File3.txt /home/itslinuxfoss/Documents

All three files are copied from “notes” to “Documents” directory that is verified in the below screenshot:

$ ls -l Documents

Method 2: How to Copy Multiple Files Linux Via Graphical User Interface?

The “GUI” Graphical User Interface is the more common way to copy multiple files simultaneously instead of CLI. For this purpose, follow the step-by-step instructions specified below:

Step 1: Select the Multiple Files

The first step is to select a list of desired files via the mouse or keyboard. After selection, press the right-click, and a menu list will pop up. Click on the “copy” option from the list to copy all the selected files.

In this case, all the files available in the “Documents” directory are selected via the mouse:

Tip: Use the shortcut key (Ctrl+C) to copy the selected files.

Step 2: Copy the Files at the Destination place

Open the destination directory and right-click with the mouse inside it. It generates a drop-down list. Navigate the mouse pointer to the “paste” option from the list:

Click the “paste” option, and in the result, the selected files from the “Documents” directory will be moved into the “Music” directory:

All the selected files have been copied from the “Documents” to the “Music” directory.

Tip: The user can also [paste the selected files by pressing the (Ctrl+V) shortcut key inside the destination directory.

That’s how the users can copy multiple files in Linux.

Conclusion

In Linux, the “cp” and the “rsync” commands can copy multiple files to a specific destination directory. In addition, these commands also support some additional options to get the output according to the requirements. This guide has briefly demonstrated the procedure to copy multiple files in Linux.