rsync #
Useful little command line tool to synchronize files across directories, even remote directories.
It compares two paths - a source and a target - for differences, and updates the target to match the source.
Basic Commands #
To copy a source
directory into a target
(note the nuance):
rsync <source> <target>
TO copy the contents of the source
into a target
directory:
rsync <source>/ <target>
Options #
To delete files on the target
that no longer exist in the source
(useful if we’re using rysnc for backups), add a --delete
parameter:
rsync --delete <source>/ <target>
To make the sync verbose, add a -v
option.
To make the sync archiving, which is to say that the sync is recursive (i.e., it goes deep down through the directory structure) and also to preserve file attribtues, use a -a
option.
TO use both archiving and verbose options, use an -av
option. This really should be a default option.
Let’s test this out #
Some commands to run to prove to yourself how this works.
cd Desktop
mkdir test
cd test
mkdir dir1
mkdir dir2
touch dir1/random_file
rsync -av dir1/ dir2
At this point, if you run tree -h
, you should see:
.
├── dir1
│ └── random_file
└── dir2
└── random_file
^ Note that random_file
, which was not created directly for dir2
, now exists within dir2
because it was rsync’d from dir1
.