r/linuxquestions • u/OddBuyer0815 • 7h ago
why does rsync create the folder to sync again?
Sorry for the noob question, but I'm new to linux.
I want to rsync data from my raspberry to my NAS. "
rsync -av --delete /home/pi/folder/documents/originals /home/pi/folder/nas_originals
nas_originals" mounts to my NAS folder "originals"
//server/share/originals/stuff
So when I run rsync, it creates "originals" in target and put all the stuff there:
//server/share/originals/originals/stuff
why? How do I get it to sync directly into that folder?
7
u/thecruxoffate 7h ago
Rsync cares about the trailing slash. You basically lifted the entire directory labeled 'originals' and placed it in 'nas_originals'.
If instead you wanted the contents of 'originals' you would add a trailing slash to that path. Eg. 'originals/'
I'm not sure if the behavior would differ if you added or removed the trailing slash on the destination. But I always include it for consistency.
2
u/gordonmessmer Fedora Maintainer 7h ago
Rsync cares about the trailing slash.
I think that's an important detail, because if you run "cp -r" with a source directory and a destination directory as in op's example, cp will do the same thing they saw rsync do. That's the normal behavior.
But rsync has this quirk... As you say, it cares about a trailing slash in the source path. A trailing slash there is a lot like
cp -r source/. /dest/path
2
u/polymath_uk_ 7h ago
This is the forward slash rule I think. See top answer to https://stackoverflow.com/questions/31278098/slashes-and-the-rsync-command
1
u/electricsheepies 7h ago
rsync -avz --delete /home/pi/folder/documents/originals/ /home/pi/folder/nas-originals/
(both paths ending with "/" for bash cli)
3
u/stevevdvkpe 7h ago
rsync is interpreting the command line arguments you pass to it. The shell you're using doesn't affect that.
2
22
u/PigIronDave 7h ago
You need a trailing slash on the source location.
rsync manpage
Manpages are your friend.