How to Copy Folder or 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.Directors inside the root directory known as subdirectories.In this tutorial, you are going to learn how to Copy the Folder / Directory in Linux.
Copy Directory Using
The basic syntax to copy the directory by using cp command:
cp -arv SOURCE_DIRECTORY DEST_DIRECTORY
Where,SOURCE_DIRECTORY: The source directory which you want to copy.DEST_DIRECTORY: The destination directory where the SOURCE_DIRECTORY directory will be copied.OPTIONS: Following are the options:
- -a: This option preserves the attributes like modification date, -time, ownership, file mode, etc.
- -r: This option will copy directory recursively.
- -v: It will verbose the output.
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
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 -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
You have successfully learned How to Copy Folder / Directory in Linux.If you have any queries regarding this then please do n’t forget to comment below.