rsync
rsync
https://linux.die.net/man/1/rsync
rsync -av --ignore-existing source_dir/ dest_dir/
rsync -av --progress --ignore-existing "/cygdrive/c/Users/username/Sync/Photos/" "/cygdrive/p/FromSync/Photos"
Flags
-a
(archive): This is a shortcut for several options (-rlptgoD
). It means:-r
: Recurse into directories.-l
: Copy symlinks as symlinks.-p
: Preserve permissions.-t
: Preserve modification times.-g
: Preserve group.-o
: Preserve owner (superuser only).-D
: Preserve device files and special files (superuser only).
- You usually want
-a
for directory copying. -v
(verbose): Optional, but recommended. Shows you which files are being transferred. You can add morev
’s (e.g.,-avv
) for more detail.--ignore-existing
: This is the key option. It tellsrsync
not to update or overwrite any file that already exists in the destination directory (dest_dir
), regardless of timestamp or size. It will only copy files fromsource_dir
that are missing indest_dir
.
Dry run
rsync -avn --ignore-existing source_dir/ dest_dir/
With cygwin
rsync -av --progress --ignore-existing /cygdrive/c/Users/vardh/Sync/temp/ /cygdrive/p/FromSync/temp
The trailing slash
This tells rsync
to copy the contents of source_dir
into dest_dir
. Without it (source_dir
), rsync
would create dest_dir/source_dir/...
.
If you use a slash at the end of the first directory, then it means: The contents of sourceDirectory
but not the directory itself. On the other hand if you ommit the use of the slash in the sourceDirectory then it means: The content of the sourceDirectory but also the SourceDirectory/ itself
.
It is important to understand how a trailing slash on the source argument functions. If there is a trailing slash then the contents of /source-path/source-dir will be copied to destination-path. If there is no trailing slash then source-dir itself will be copied to the destination and its contents will be another level down in the destination hierarchy.
So if you want to replicate one path to another include the trailing slash as follows:
rsync -av /sourcepath/sourcedir/ /duplicatpath/sourcedir/