File synchronization compares and synchronizes files and directories between your local computer and the remote server, making sure both locations contain the same files and directories.
sync [options] <local path> <remote path>
local path
and remote path
you can use either an absolute path or a relative path.
Options
--direction,
-d
: synchronization type:
localtoremote, l
: one-way synchronization replicating local files noton the server, removing files on the server that don’t exist on the local
directory.
remotetolocal, r
: one-way synchronization replicating remote files
on the local directory, removing files on the local directory that don’t
exist on the server.
bidirectional, b
: two-way synchronization replicating local files
not on the server and replicating remote files on the local directory,
no files are deleted.
--exists,
-e
: allow to specify how to handle files that exist on both sides:
ignore, i
: just ignore the files.
newer, n
: upload or download if the source is newer than the target.
size, s
: upload or download if file sizes are different. Ignored in the
bidirectional
type.
sizeornewer, w
: upload or download if source is newer or file sizes are dif-
ferent. Ignored in the bidirectional
type.
--recursive,
-r
: synchronize recursively files and subdirectories.
--preview, -p
: allows to see the expected result of synchronization without actually executing it. No changes take place.
--exclude
: exclusion condition. Files matching the condition are ignored. See Filter Files and Directories.
--match
: exclusion condition match type. See Filter Files and Directories.
--rootonly, -t
: apply exclusion condition only to entries in synchronization root. Requires --exclude
and --recursive
options.
Note: The path parameters are always local first and remote second, regardless of the direction option.
Examples
Copy new and updated local files to server:
sync --direction localtoremote --recursive --exists newer /Files/website/
public_html /public_html
Backup remote files to local:
sync --direction remotetolocal --recursive --exists newer /Documents/backup /
files/documents