System Administration

How to Copy a Folder in Linux?

The files and folders are commonly used in any operating system. At times, your folder contains some crucial data, and you prefer to keep several backup copies. The first solution that comes to our mind is to copy that folder somewhere else. Therefore, in this article, our target is to figure out all the methods of copying a folder in Linux, i.e., both the CLI-based methods and the GUI-based methods.

Note: For explaining the different methods of copying a folder in Linux, we have made use of Linux Mint 20.

Methods of Copying a Folder in Linux:

Following are the four most common methods of copying a folder in Linux:

Method # 1: Using the Linux GUI:

This is the easiest method of copying a folder in Linux, which is also very commonly used in other operating systems. You need to perform the following steps to copy a folder in Linux using this method:

First, we have to create a folder for demonstration in our Home directory named “CopyFolder”.

The folder that we have created is shown in the image below:

For launching a pop-up menu, you should right click on this folder. Once the menu is launched, we will choose the “Copy” option from this menu, as shown in the following image:

In this example, we intend to copy our “CopyFolder” to the “Documents” folder. Therefore, we will double click on the “Documents” folder to open it. Then while on the “Documents” folder, we will right click on its empty space to launch a pop-up menu again. Now we will select the “Paste” option from the menu, which has just launched as highlighted in the image shown below:

After doing this, you will notice that your “CopyFolder” or any other selected folder has been copied to the “Documents” folder or any other folder that you have chosen, as shown in the following image:

Method # 2: Using the “cp” Command:

This method and the two other methods shown below are Linux Mint 20 terminal based. We will follow the steps mentioned below for making use of this method copying a folder in Linux:

Since this method is terminal-based, therefore, we will launch the Linux Mint 20 terminal as shown in the following image:

You should enter the following command in your terminal once it has been launched:

$ cp –r NameOfFolderToBeCopied DestinationPath

Here, you have to provide the actual name of the folder to be copied instead of NameOfFolderToBeCopied, and the actual path to where you want to copy that folder instead of DestinationPath. In the scenario which we are discussing, we intend to copy the “CopyFolder” to our “Documents” folder. Hence, we have written “CopyFolder” instead of NameOfFolderToBeCopied. Also, the path to the “Documents” directory instead of DestinationPath, as shown in the image below:

Once you have pressed the “Enter” key to execute the above-mentioned command, your desired folder would have been copied to the specified destination. You can also confirm if the desired operation has taken place or not by running the following command in your terminal:

$ ls –l DestinationPath

Here, you should provide the path to the place where you have copied your folder instead of the DestinationPath.

Running this command will list down all the contents of the “Documents” directory, which will also contain the folder that you have just copied, i.e., the “CopyFolder”, as shown in the image below:

Method # 3: Using the “rsync” Command:

In using the “rsync” command to copy a folder in Linux Mint 20, we will have to perform all the steps listed below:

First, we need to install the “rsync” command, if it has not already been installed, by executing the following command in our terminal:

$ sudo apt-get install rsync

Once this command has been installed on your system, your terminal will reflect the output shown in the image below:

Now, when the “rsync” command has been successfully installed on your system, you have to execute the following command in the terminal:

$ rsync –avz NameOfFolderToBeCopied DestinationPath

Here, you have to provide the actual name of the folder to be copied instead of NameOfFolderToBeCopied and the actual path to where you want to copy that folder instead of DestinationPath. In the scenario which we are discussing, we intend to copy the “CopyFolder” to our “Documents” folder. Hence, we have written “CopyFolder” instead of NameOfFolderToBeCopied. As well as the path to the “Documents” directory instead of DestinationPath as shown in the following image:

Once you have executed this command, your terminal will show you a confirmation message depicting that the specified operation has been successfully performed, as shown in the image below:

You can also confirm it by executing the “ls” command, as described in the method above.

Method # 4: Using the “scp” Command:

This is yet another terminal-based method of copying a folder in Linux, which can be followed in the manner shown below.

The “scp” command can be used to copy a folder in Linux in the following way:

$ scp –r NameOfFolderToBeCopied DestinationPath

Here, you have to provide the actual name of the folder to be copied instead of NameOfFolderToBeCopied and the actual path to where you want to copy that folder instead of DestinationPath. In the scenario which we are discussing, we intend to copy the “CopyFolder” to our “Documents” folder. Hence, we have written “CopyFolder” instead of NameOfFolderToBeCopied. Also, the path to the “Documents” directory instead of DestinationPath as shown in the following image:

Once you have executed this command, you can confirm if your folder has been copied to the specified destination or not by running the “ls” command once again.

Conclusion:

All the methods demonstrated in this article are extremely easy to follow. These methods are capable of copying a folder to any specified destination within a few seconds. By following any of these methods, you can copy as many folders as you want and at any place of your choice while using the Linux operating system.

About the author

Aqsa Yasin

Aqsa Yasin

I am a self-motivated information technology professional with a passion for writing. I am a technical writer and love to write for all Linux flavors and Windows.