Copy Files and Directories in Linux with SSH using SCP, CP, and

As a server administrator, even simple tasks can benefit from a new perspective. To that end, today’s article talks about multiple ways to copy an entire directory and its files on Linux. To do so, we’ll explore three commands: cp, scp, and rsync.


You can copy files and folders within the same file system on Linux using the cp command. The -r argument tells cp that you want to copy a directory recursively, which also copies the contents of the folder. For example:

cp -r /path/to/source/directory /path/to/destination/directory

The result is that the directory, including all its contents and subdirectories, will be copied to a different folder on the local server

. scp Meanwhile, the scp command

will allow you to copy files and directories using an encrypted SSH connection. This allows for greater security and data integrity, and is commonly used to copy directories between remote servers, although it can also be used locally. To copy an entire directory using scp, you can also use the -r flag in the same way you did with the cp command. Example

: scp -r /path/to/source/directory user@remotehost:/path/to/destination/directory The

result here is that the “directory” directory will be safely copied to the destination folder in “remotehost”

rsync The rsync command

allows you to replicate files and directories while maintaining ownership and permissions. It also offers additional capabilities such as compression and incremental updates. The -a switch enables “archive” mode, which allows you to use rsync to transfer a directory while retaining ownership and rights. For example:

rsync -a /path/to/source/directory /path/to/destination/directory

This example shows how to use rsync to copy directories to the local computer. You can also use it in the same way as shown for scp if you want to use rsync to copy directories to remote servers.

That’s all!

The above is one of the most basic and common ways to use these commands. We recommend that you use Linux man pages for each command in order to learn about its more advanced features.

In conclusion, it is useful for a server administrator to be able to copy an entire directory and all its contents using a variety of techniques. To copy files and directories, the cp, scp, and rsync commands provide specific options and features; Depending on your circumstances, one may be preferable to the others.

Love servers?

We do! If you have questions related to Linux and servers, big or small, IOFLOOD can help. Our dedicated servers offer a range of solutions to meet your needs, and our team of experts is always available to provide support and guidance for all your server-related questions.

To learn more about our dedicated servicesand how we can help you with your specific needs, contact us at sales[at] or visit our website at Our team is ready to answer your questions and help you find the best server for your needs.

Contact US