How to Copy Folder/Directory in Linux

Copy Folder/Directory in Linux

Folder or Directory contains a set of files. A directory can contain multiple files. The top-level main directory known as the root directory. Directories inside the root directory known as subdirectories. In this tutorial, you are going to learn how to Copy the Folder/Directory in Linux.

In the below example, it will copy the directory demo and all the files inside the directory to the demo2 directory. This process is done by preserving attributes with verbose output.

cp -arv demo demo2

The output should be:

How to Copy Folder or Directory in Linux – cp command example

Copy Directory using rsync command

You can copy files using rsync command across the network at a faster speed than cp command. rsync Command also archives the files and then copies it. So it reduces the size and time. This command is useful in transferring large files.

Following is the basic syntax to copy files using rsync command:

rsync -azv SOURCE_DIRECTORY DEST_DIRECTORY

In the above command -a (Archive Mode) option copies files recursively with all its permission information. -z option compresses the data so the file sizes are reduced and will take less time. Option -v will just verbose the output.

In the following example, all the files inside the directory demo1 will be copied to the demo3 directory. This process completes by preserving attributes with verbose output.

rsync -azv demo1 demo3

The output should be:

How to Copy Folder or Directory in Linux – rsync command

Conclusion

You have successfully learned How to Copy Folder/Directory in Linux. If you have any queries regarding this then please don’t forget to comment below.