How To Recursively Copy Remote Files in Linux

Sometimes, you may encounter copying deleted files in your Linux distribution. Several popular tools are used for this: scp and rsync. This article will describe specifically how each tool works.

Working with Scp

Scp is a special tool that can be used to securely copy files to and from a remote computer using the Secure Shell (SSH) protocol. Scp stands for Secure Copy. The basic syntax for the scp command is as follows:

scp <option> <source> <destination>

To copy files recursively, you need to use the -r option. For example, the command below will recursively copy the contents of the my / draft directory to the / backup directory on the remote server. A valid username on the remote server is required.

scp -r / draft redhat8@185.186.244.123:/backup

Here’s another example of recursively copying the contents of the /backup/draft directory from a remote server to a directory on my local machine

scp -r rredhat8@185.186.244.123:/backup/draught /recovered

Working with Rsync

The rsync tool, which stands for how remote synchronization is used to copy files between local or remote computers, and between computers on a network by comparing modification times and file sizes. It is commonly found on Unix-like operating systems. Rsync is written in C as a single threaded application. The basic syntax for the scp command is as follows:

rsync <options> <source <destination>

The ability to copy files recursively is denoted by -r. can synchronize Unix clients with a central Unix server using rsync / ssh and standard Unix accounts. It can be used in a desktop environment, for example, to efficiently synchronize files with a backup on an external hard drive. A scheduling utility such as cron can perform tasks such as automatic rsync encryption-based mirroring between multiple hosts and a central server. For example, the command below will recursively copy the contents of the my /draft directory to the /backup directory on the remote server. A valid username on the remote server is required.

rsync -rav /draught1.1 redhat8@185.186.244.123:/backup1.1

The following example recursively copies the contents of the /backup1.1/draught1.1 directory from the remote server to a directory on my local machine

rsync -rav redhat8@185.186.244.123:/backup1.1draught1.1 /recovered2

Was this article helpful?

Related Articles

Leave A Comment?