How to Copy Files and Directories in Linux?

There are different methods to copy files and directories in Linux; usually, the core functionality of a Linux distribution is associated with terminal-based operations; however, the GUI can also be installed and used to perform the operations. Both methods can be used to copy files and directories in Linux, and this post has briefly demonstrated the possible methods to copy files and directories in Linux and will explain the following sections:

Let’s start with the terminal method first!

Method 1: Copy Directories and Files using the Terminal in Linux

We all know that all the Linux distributions are command-line based and are managed by running different commands. For copying files and directories, we can use the cp command utility whose syntax of using in the Linux distributions is:

$ cp [options] [file/directory to be copied] [new name for the copied file]

To understand the above syntax, we will use different examples in Linux.

How Do You Copy Files Using the cp Command in Linux?

We have different files named “myfile1”, “myfile2”, “myfile3”, and “myfile4”, on which the usage of the cp command will revolve in this article. Let’s use them to apply the “cp” command to copy files.

Example 1: Copy a Sigle File

We will use the cp command to copy the “myfile1” to the “Downloads” directory (and the name is changed to “myfile1_copy”):

$ cp myfile1 /home/itslinux/Downloads/myfile1_copy

Now, to verify the execution of the above command, use the cat command to display the contents of the “myfile1_copy”:

$ cat  /home/itslinux/Downloads/myfile1_copy

Note: The “ls” command can also be used for the verification of the execution of the “cp” command.

Example 2: Copy Multiple Files

We can also copy multiple files using a single command, and to do so, the three files named “myfile1”, “myfile2”, and “myfile3” will be copied to the “Downloads” directory using the command written below:

$ cp myfile1 myfile2 myfile3  /home/itslinux/Downloads/

To verify, display all the contents of the “/home/itslinux/Downloads/” using the ls command:

$ ls /home/itslinux/Downloads/

The files have been copied.

How Do You Copy Directories Using the cp Command in Linux?

The cp command can also copy the directories in Linux distributions; for this, we have a directory in the home directory with the “myFolder” name.

Example 1: Copy One Directory

To copy the directory with all its files, we can use the cp command with the “-R” or “-r” option:

$ cp -r myFolder /home/itslinux/Downloads/

List down the contents of the Downloads directory to confirm the execution of the above command:

$ ls Downloads

The directory has been copied and to learn more about the cp command and other ways to copy files, visit the link.

Example 2: Copy Multiple Directories

To copy the multiple directories in Linux, the cp command can be used with its -r flag; for example, we copy the “mydirectory1” and “mydirectory2” to “/home/itslinux/Videos/” using the command:

$ cp -vr mydirectory1 mydirectory2 /home/itslinux/Videos/

Note: For more details on cp command. Read this article: cp Command in Linux

Method 2: How to Copy Directories and Files in Linux Using the GUI?

Another way to copy files and directories in Linux is through the Graphical user interface. This method is the same for the directories and files. Hence we will apply this method to copy files. Select the files/Directories you want to copy and then, press the right mouse button, then choose the “Copy” option:

After this, go to the directory where you want to paste it and choose “Paste” after pressing the Right button of the mouse:

Doing so, the files are pasted into the target directory as can be seen below:

That’s all from this post.

Conclusion

To copy files and directories in Linux, we can use the command-line interface or the GUI method, and the “cp” command utility in Linux can be used for copying the files/directories from the terminal. However, the GUI method is quite simple, select and copy the files/directories and paste them in the desired location and this Linux post has guided you to copy files and directories through CLI and GUI.