rsync - Linux File Copying Tool
rsync is a convenient Linux file copying tool used to transfer files remotely and locally. rsync is more efficient than scp because it only copies files that have changed. rsync also offers many options to customize the tool for countless situations.
Mouse Hover over the ➼ blue text in the descriptions to highlight the command above.
Basic Command Configuration
rsync [options] [source] [destination]
➼ rsync - Command to use the rsync tool
➼ options - Any specifications you want to add to the command
➼ source - The location of the file you want to copy
➼ destination - The location where the copy should go
Transfer Locally - No Options
There is a file called battle-back-story.odt in my Documents directory, and I want to put a copy in my code_practice directory.
$ rsync /home/candy/Documents/battle-back-story.odt /home/candy/code_practice
Transfer Local to Remote
Basic Command Configuration
rsync [option] [LOCAL_SOURCE] [REMOTE_USER@REMOTE_HOST:REMOTE_DESTINATION]
Example - No Options
There is a file named linux10.txt in my local code_practice directory. I want to put a copy of it in a remote server. The ip address of the remote server is 192.168.1.68, the user is commander and I want to put it in commander's home directory.
rsync /home/candy/code_practice/linux10.txt commander@192.168.1.68:/home/commander
Transfer Remote to Local
Basic Commander Configuration
rsync [OPTION] [REMOTE_USER]@[REMOTE_HOST]:[REMOTE_SOURCE] [LOCAL_DESTINATION]
Example - No Options
We are copying a file on a remote server with ip address 192.168.1.68 and user name commander. The remote file is called cherry.php and is located in commander's home direcory. We want a copy of this file in our local code_practice directory.
rsync commander@192.168.1.68:/home/commander/cherry.php /home/candy/code_practice/
Copying Directories with -r
To transfer directories, we use -r (or --recursive). -r is the recursive argument in Linux commands. That means the command will effect that directory as well as all the files and directories located within that directory.
Example
rsync -r /home/candy/code_practice commander@192.168.1.68:/home/commander
More Common Options
Archive
Archive (-a or --archive) is commonly used to back-up directories. It recursively copies the entire directory with:
- Files and directories
- Permissions
- Ownership
- Modification time
- Symbolic Links
rsync -a /home/candy/code_practice commander@192.168.1.68:/home/commander
--progress
By using the --progress option, progress will be shown during transfer.
$ rsync -a --progress /home/candy/code_practice commander@192.168.1.72:/home/commander
-v, --verbose
The verbose option (-v or --verbose increases the amount of information shown. It will show the file path for every command copied.
$ rsync -r -v /home/candy/test commander@192.168.1.72:/home/commander/
-z, --compress
Reduces bandwidth by compressing file data.
-b, --backup
Files in your destination are renamed and saved, not deleted.
-q
Quiet (-q) decreases that amount of information shown. It will only show error messages.
Many More Options
There are many more options you can use with the rsync tool. To see a full list, type man rsync in your terminal or go to rsync manual.