loading...
Cover image for rsync - 10 examples in 11 days (Day 01)

rsync - 10 examples in 11 days (Day 01)

jmr_code_social profile image Jorge Marquez Updated on ・1 min read

Day 01

10 examples in 11 days

Sync Files and Directories Locally

Let's say we have a directory called Users. Inside of this folder we have various .json files with user settings. This is how our tree will look like:

  • Users
    • user01.json
    • user02.json
    • user03.json

To be sure we sync all our files and they were copied correctly, we can check the file size of each one. Inside the users folder and using the stat command with the -c option and the %s %n arguments to show only the size and the name of each file:

iamgroot@laptop:~$ stat -c "%s %n" ~/Users/*
92 user01.json
57 user02.json
69 user03.json

As you can see, each file have different size and they are displayed in bytes ie: 92bytes for user01.json file.

Now that we know what we have, let's sync it:

iamgroot@laptop:~$ rsync -vhr /home/iamgroot/Users /home/iamgroot/SyncFiles

sending incremental file list
Users/
Users/user01.json
Users/user02.json
Users/user03.json

sent 478 bytes  received 77 bytes  1.11K bytes/sec
total size is 218  speedup is 0.39

Let's verify if the folder and its files were copied to the destination folder

iamgroot@laptop:~$ ls -h ~/SyncFiles && stat -c "%s %n" ~/Users/*

92 user01.json
57 user02.json
69 user03.json

We can see we have the Users folder copied, all files are inside of it and the file size are exactly the same as the source


Ok, that'll be for today's example, thanks for reading!!!

Follow, ❤ or 🦄

Discussion

pic
Editor guide
Collapse
_garybell profile image
Gary Bell

Looking forward to the rest of the series. On my todo list is set up sync from my NAS to an external hard drive for safe keeping

Collapse
jmr_code_social profile image
Jorge Marquez Author

Remote sync will come up shortly. Hang in there will be soon hehe.
;)