Linux Commands Ubuntu

How to Copy an Entire Folder in Linux/Ubuntu?

How do Copy an Entire Folder in Linux Ubuntu

Copying files and folders is one of the essential and most frequent tasks we do every day while working on organizing data, creating backups, sharing files, editing, etc. In Linux distributions including Ubuntu, this task can be accomplished via the command line tools as well as GUI (Graphic User Interface). In this article, we will demonstrate different methods to copy single and multiple folders/directories in Linux/Ubuntu 22.04 LTS.

Prerequisites

In order to follow this article, we will require

  • System with Ubuntu 22.04 LTS Installed.
  • Basic knowledge of command line usage.

How to Copy an Entire Folder in Linux/Ubuntu?

An entire folder is copied in Linux/Ubuntu 22.04 using the following methods:

  • Method 1: Via Command Line
  • Method 2: Via Ubuntu’s Desktop File Manager

Method 1: Copy a Folder/Directory via the Command Line

In this section, we will demonstrate two popular command line tools: cp and rsync to copy a folder.

How to Copy a Folder/Directory via the “cp” Command?

cp” is one of the most commonly used command line tools. cp copies single or multiple folders/directories from a source directory to a destination directory.

How to Copy a Single Folder/Directory via the “cp” Command?

The basic syntax to copy a single directory using the “cp” command is:

$ cp -r [source-directory-path] [destination-directory-path]

In the above syntax, “cp” is the main keyword followed by the “-r” flag, which denotes “recursive”. The “r” flag copies all source directory files to the destination path.

Consider a scenario of moving a folder named “Files” from the “Home” folder to the “Documents” folder. We can navigate to the “Home” folder and check the contents of the “Home” folder as below:

$ ls

Further, the contents of the “Files” folder can be seen by executing the following code:

$ ls -l Files

We can copy a single folder “Files” along with all its contents from the “Home” directory to the “Documents” directory along with renaming the copied file to “MovedFiles” by running the following command:

$ cp -r /home/linuxuser/Files /home/linuxuser/Documents/MovedFiles

We can verify that the folder “MovedFiles” is copied by navigating to the “Documents” folder via the cd command:

$ cd Downloads

$ ls

From the below image, it can be observed that the folder “MovedFiles” is copied.

We can also verify the contents of the folder as follows:

$ ls -l MovedFiles

The below image verifies that all contents of the folder are successfully copied:

How to Copy Multiple Folders Using cp Command?

We can copy multiple folders simultaneously with the “cp” command as well. The basic syntax to copy multiple folders using the “cp” command is:

$ cp -r [source-directory-path-1] [source-directory-path-2] [source-directory-path-3] [destination-directory-path]

Consider the scenario of moving “Files1”, “Files2”, and “Files3” from the “Home” directory to a Directory named “Extra” in the “Documents” directory. We can check the contents of the Home directory by executing the below command:

$ ls

In the following code block, first, we use the cd command to access the “Documents” directory. Then, we create a directory “Extra” in that directory using the mkdir command:

$ cd Documents

$ mkdir Extra

We can copy multiple files, i.e., “Files1”, “Files2”, and “Files3” along with all their contents from the “Home” directory to the “Documents” directory by running the following command:

$ cp -r /home/linuxuser/Files1 /home/linuxuser/Files2 /home/linuxuser/Files3 /home/linuxuser/Documents/Extra

The cursor moves to the new line indicating that the cp command is executed successfully:

We can verify that the files are copied by navigating to the “Extra” folder via the cd command and then executing the “ls -l” command:

$ cd Documents

$ ls -l Extra

From the above image, it can be seen that all the File1, File2, and File3 are successfully copied into the Extra folder.

How to Copy a Folder/Directory via the “rsync” Command?

Rsync” is a command line utility that copies single or multiple directories from the source to the destination directory.

How to Copy a Single Folder/Directory via rsync Command?

The basic syntax to copy a single folder via the “rsync” command is:

$ rsync -a [source-directory-path] [destination-directory-path]

In the above syntax, “rsync” is the main keyword followed by the “-a” flag, which transfers/copies all source directory files to the destination directory.

Consider a scenario of moving a folder named “Extra” from the “Documents” folder to the “Downloads” folder. We can navigate to the “Extra” folder and check the contents as follows:

$ cd Documents

$ ls -l Extra

As seen from the below image, the Extra folder contains three files, File1, File2, and File3.

We can copy a single folder “Files” along with all its contents from the “Extra” directory to the “Downloads” directory by running the following command:

$ rsync -a /home/linuxuser/Documents/Extra /home/linuxuser/Downloads

We can verify that the file is copied by navigating to the “Downloads” folder via the cd command and checking the contents of the Extra directory:

$ cd Downloads

$ ls -l Extra

From the below image, we can see that the folder “Extra” is copied along with all its contents.

How to Copy Multiple Folders Using rsync Command?

We can copy multiple folders simultaneously with the rsync command as well. The basic syntax to copy multiple folders using the rsync command is:

$ rsync -a [source-directory-path-1] [source-directory-path-2] [source-directory-path-3] [destination-directory-path]

Consider the scenario of moving “Files1”, “Files2”, and “Files3” in the “Extra” directory to a Directory “rsync” in the “Documents” directory. We can check the contents of the Extra directory by navigating to the Extra directory:

$ cd Downloads

$ ls -l Extra

We can copy multiple files, i.e., “Files1”, “Files2”, and “Files3” along with all their contents from the “Extra” directory to the “rsync” directory by running the following command:

$ rsync -a /home/linuxuser/Downloads/Extra/Files1 /home/linuxuser/Downloads/Extra/Files2 /home/linuxuser/Downloads/Extra/Files3 /home/linuxuser/Documents/rsync

We can verify that the files are copied by navigating to the “rsync” folder via the cd command:

$ cd Documents/rsync

$ ls -l

From the below image, it can be seen that File1, File2, and File3 are successfully copied into the rsync folder.

Method 2: Copy a Folder/Directory Via Ubuntu’s Desktop File Manager

In this section, we will demonstrate how to copy a single folder and multiple folders with ease using Ubuntu 22.04 LTS Desktop File Manager.

How to Copy Single Folder/Directory Using Ubuntu’s Desktop File Manager?

Consider a scenario of copying a folder “Files” in the Home Folder to the “Documents” folder. We can accomplish it by the steps mentioned below:

Step 1: Select a Folder/Directory

We will navigate to the location where the desired folder exists, i.e., the “Home” folder:

After that, select the desired folder “Files” and press “right-click” by utilizing the mouse. It will generate a drop-down menu list. From the drop-down menu list, we will select the “Copy” option as shown below:

In the above image, a Folder named “Files” in the Home directory is copied.

Step 2: Copy the Folder/Directory at Desired Folder/Directory

We will then navigate to the desired directory, i.e., the “Documents” where we would like to copy the folder. A folder can be copied by pressing the “right-click” of the mouse. It will generate a drop-down menu list. From the drop-down menu list, we will select the “Paste” option as shown below:

The desired folder named “Files” will be copied from “Home” to the “Documents” folder as shown below:

Similarly, we can copy multiple folders by following the above steps.

How to Copy Multiple Folders/Directories Using Ubuntu’s Desktop File Manager?

Consider a scenario of copying folders ”Files1”, “Files2”, and “Files3” in the “Extra” Folder to the “Downloads” folder. We can accomplish it by the steps mentioned below:

Step1: Select Folders/Directories

We will navigate to the location where the desired folder exists, i.e., in the “Extra”, and will select multiple folders and press the “right-click” of the mouse. It will generate a drop-down menu list. From the drop-down menu list, we will select the “Copy” option as shown below

In the above image, Folders: “Files1”, “Files2”, and “Files3” in the Extra directory are copied.

Step 2: Copy the Folders/Directories to the Desired Directory

We will then navigate to the desired directory, i.e., the “Downloads” directory, where we would like to copy the folders. The folders can be copied by pressing the “right-click” of the mouse. It will generate a drop-down menu list. From the drop-down menu list, we will select the “Paste” option as shown below:

The desired folders: “Files1”, “Files2”, and “Files3” will be copied from the “Extra” to the “Downloads” folder as shown below:

Conclusion

Single and multiple folders can be copied in the command line by using “cp” and “rsync” command line tools while files can be copied with ease using “Copy” and “Paste” using Ubuntu’s Desktop File Manager. In this article, we discussed different ways of copying single and multiple folders in Linux/Ubuntu 22.04 LTS.

Similar Posts