I am trying the following command using rsync to copy only files that
- are new
- have a different size
rsync -niav --size-only /home/me/source/Electronica /media/externalDrive/dest/Electronica
However, this dry-run results in the following output:
>f+++++++++ Electronica/music/AlbumArt_{F0CB439F-A1FC-47DB-A698-C561191F3FDE}_Large.jpg
>f+++++++++ Electronica/music/AlbumArt_{F0CB439F-A1FC-47DB-A698-C561191F3FDE}_Small.jpg
>f+++++++++ Electronica/music/Folder.jpg
which I interpret to mean that those files are copied. But they have the same size! (The times and flags are different, though). Also the rsync refers to an external hard-drive (with a different format).
I also tried the following commands:
rsync -niav --size-only --ignore-times /home/me/source /media/else
rsync -niav --size-only --ignore-existing /home/me/source /media/else
But still, these files are shown in the same way, meaning they would have copied. What else can I try?
And what is wrong with the main page description?
--size-only skip files that match in size
Best Answer
You've fallen into
rsync
's classical "trailing slash trap":If the source path does not end with a slash,
rsync
will copy the source directory. If you intend to copy the contents of the source directory, it needs to end with a slash.Let's look at an example, assuming you want to copy a file at
/home/me/source/Electronica/music/Folder.jpg
:will copy the
Electronica
directory from the source to the destination, so it will create/media/externalDrive/dest/Electronica/Electronica/music/
and putFolder.jpg
in there.will copy the contents of the
Electronica
directory, so it will replicate themusic
directory under/media/externalDrive/dest/Electronica/
(if it doesn't exists) andFolder.jpg
will end up at/media/externalDrive/dest/Electronica/music/Folder.jpg
.To make matters more confusing, it does not matter if the destination path ends with a slash.
Just make a habit of ending all
rsync
paths with a slash, then you'll be safe from any nasty surprises.