

Tip: If the list of patterns for either of the options is huge, you can store it in a file and you can pass their names to the –include-from and –exclude-from option. You can use regular expression as a pattern. The above command copies all the files with extension. rsync A/ Backup-A-dir/ -include=*.py -exclude=*.tmp.py Each option should be given a pattern after ‘=’ sign. –include and –exclude option can be used. If you need (or do not need) to transfer files whose name match a pattern, You should delete source only if enough copies are made and the data is not needed anymore in the source. You should be careful with the above command.

rsync A/ Backup-A-dir/ -remove-source-files If you need to delete the files in source once the transfer is complete, –remove-source-files option should come in handy. To maintain both endpoints (directories or files) at the same state with the same files and no extras on either side, just append the –delete option to the original command. If you want that, you’ll have to use two-way sync.

But if the system had some extra files that were not on the source, those will not be deleted by One-way sync. The above command copies the files from the source to the destination. Note that the source location and destination location can either be local file system paths or remote system(ssh) paths. To sync files between a remote system and a local system, the command is similar. This is why it is called as one-way sync.

This won’t copy any extra files in Backup-A-dir into A that are not in A initially. This command copies the files (if changes found) of directory A into Backup-A-dir. To copy local files from directory A into Backup-A-dir, rsync A/ Backup-A-dir/ But copying A/ will copy only the files in A into the destination. So copying A will create a new directory in the destination and then copies the files in A. Using A/ will refer to all the files in directory A and not directory A itself. If you have a directory A, use “A” to mention it not “A/”.
#Linux grsync how to
Let’s see how to use rsync command with some helpful examples. Where source and destination can be local paths or remote paths in the format :path/to/file The rsync command has the following structure rsync Source Destination
#Linux grsync install
sudo apt install rsync Practical examples of rsync command in Linux In Ubuntu and Debian, you can install rsync with the following command. If you don’t have rsync installed, you can install it using your package manager. One can resume incomplete transfer in rsync while scp doesn’t allow it.But this should be considered when there is no security risk of transferring without encryption. rsync can also work without encryption.So a better speed is guaranteed in rsync. rsync copies only the files that are changed while scp copies every file and overwrites them if needed.scp, short for secure copy, is also used for copying files between two remote system over ssh.īut rsync has certain advantages over scp that make it a better choice. I already showed you some practical examples of scp command. The single biggest advantage of rsync is that it copies only the changed files and thus reduces the CPU consumption and saves the bandwidth and time while copying files. Rsync (Remote Sync) is a synchronization tool for copying files and directories in a system or between systems.
