Copy Files and Folders in Linux

How to Copy Files and Folders from one Directory to Another in Linux

There are many ways to copy files from one directory to another in Linux.

Using GUI

You can copy files/folder through any file manager application. Right-click on the file/folder and select copy from the context menu, then go to the directory where you want to make a copy, right-click and choose the paste option.

Using cp command

If you are comfortable using the terminal, you can use the “cp” command to copy.

The syntax of this command is as follows:

cp -r [source-file-path] [destination-path]

[source-file-path] specifies the source of the files/directories you want to copy, and [destination-path] specifies where you want to copy the file/folder.

“-r” stands for recursive and is used while copying folders and subfolders.

Let’s see some example

Copy file from one directory to another

cp folder1/file1.txt folder2

Copy file with a different name

cp folder1/file1.txt folder2/file2.txt

Copy folder and its subfolder

cp -r folder1/subfolder1 folder2

That’s it! The files or folders should now be copied from the source to the destination directory.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top