m4r4v
Posted on July 16, 2020
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 🦄
Posted on July 16, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.