5 ms·
rsync is what taught me to respect the trailing slash.
by colordrops 5y ago
rsync is what taught me to respect the trailing slash.
- 6LLvveMx2koXfwn 5y agoCame here to say exactly that, smiled at yours being the first comment. And further I used to hate rsync's parsing of the trailing slash and now have come to love it, I don't know when the transition happened.
- l33tman 5y agoI'm still scared every time I use rsync because of that and have to thoroughly check the man-page examples :)
- thwarted 5y agoNo need to fear! Use --dry-run to confirm your command line before making the changes. It's documented in that very man page!
- 0des 5y agoI have a list of aliases I pass to my minions, one is to alias rsync with this, and the real rsync is aliased as rsyncplz
- teddyh 5y agoThat kind of stuff sounds good, but it’s dangerous. You risk getting used to it, and then getting hosed when you’re on a normal system. Some people use a similar thing where they set "rm" as an alias to "rm -i", i.e. ask interactively before removal of each file. I once heard a story about some SunOS consultant who was used to "rm" being an alias for "rm -i", and the first thing this consultant did, as root, was to "cd /etc" and then "rm *".
- layer8 5y agoIn principle this could be solved by having two aliases `rsync-dry-run` and `rsync-for-real`, and aliasing `rsync` to `echo "Use rsync-dry-run or rsync-for-real“`.
- 0des 5y agoThat's great, I'll do that now. Thanks!
- justinsaccount 5y agoOne of my first introductions to the fact that GNU getopt is much different from BSD/UNIX getopt was running `rm * -i` on Solaris. Instead of prompting me for which files to delete, it removed all of my files and then printed an error about failing to remove the non existent file "-i".
- vq 5y agoEvery time I use one of the --delete/--delete-* arguments I first try with --dry-run since I don't trust myself that I got the trailing slashes in the right spot.
- matejn 5y agoI've recently had to copy a bunch of files over two Windows Servers and was pleasantly surprised by robocopy's (basically Windows' rsync) solution to this dilemma: the first two parameters always only refer to directories, and then you can list specific files starting with the third parameter. This way there can be no confusion whether you're copying the contents of a directory or the whole directory, and you can't create a duplicated directory within your destination by mistake.
- paol 5y agoI love rsync for what it can do, but I hate that with a passion. It's terrible design that should have never seen the light of day.
- deleted 5y ago[deleted]
- mhalle 5y agoI end up reposting this comment whenever rsync's slash treatment gets mentioned. rsync has "weird" syntax for a reason. Unlike other unix-like commands, it treats trailing slashes as significant AND consistently. If a directory has a trailing slash, it means "contents" of the directory". No slash means "the directory itself". These are two different concepts, and a program that copies directories should take the difference into account. scp (and cp, for that matter) don't take this difference into account. That leads to gotchas with recursive (-r) copying. Most importantly, scp isn't idemopotent: scp -r fromdir todir If todir doesn't exist, scp will copy the contents of directory fromdir to a new directory named todir. Execute the same command again (now that todir exists), and scp will copy fromdir to todir/fromdir . On the other hand: rsync -a fromdir/ todir will always copy the contents of fromdir into a directory named todir (effectively, a directory rename operation), whether todir exists or not. rsync -a fromdir todir will always copy the directory fromdir into the directory todir, whether todir exists or not. These rsync operations are idempotent, which it important because rsync is designed to incrementally re-sync directories. It is expected that it will commonly be run more than once, which is why it needed to address this IMHO fundamental bug/limitation in cp and scp.
- leephillips 5y agoGreat explanation! I prefer rsync to cp, etc., because of this consistency, but I never appreciated the idempotency implications.
- nijave 5y agoIsn't that problem also solved with the `dir/.` syntax? Adding the `.` signifies content versus the directly itself I think it's `cp` that uses that syntax
- adrian_b 5y agoActually a trailing slash is significant not only in rsync, but in most other command-line utilities. Unfortunately, rsync lacks a helpful option like the "--strip-trailing-slashes" of GNU cp and mv. I never use bare cp or mv, but only aliases which replace their undesirable default options with other more useful options, including "--strip-trailing-slashes", which makes the presence or absence of a trailing slash irrelevant.
- gjvc 5y agosame. my rule of thumb is: always always always use the trailing slash on source/ and target/ paths and it will always do the right thing.
- nickcw 5y agoWhen I was implementing rclone which implements a lot of rsync's functionality but for cloud storage, I deliberately didn't copy the trailing slash feature. This annoys people who know rsync well, but newbies are very happy with it! Even though I know rsync extremely well I am super careful with this. Test first with `--dry-run`!
- the_svd_doctor 5y agoThanks so much for rclone. Awesome piece of software.