Does `ditto` follow symlinks?

michaelsanford

Translator, Web Developer
I know this might be a dumb question, and the answer's probably yes, but does ditto follow links and copy their contents as well, or does it just make a symlink to the original item on the destination and not follow?

I ask because I have a symlink in my home folder that points to my back-up firewire drive. Now if I back up my home folder to my back-up drive... :( kaboom?

Thanks!
 
My impression from the manpage is that it doesn't really do either - it copies the symlinks exactly as they are.

I apologize if I'm explaining what you already knew, but: symlinks just contain text, which is substituted into the path to be opened. If the symlink text is absolute (i.e. starts with /) then the text replaces the portion of the path resolved so far. If the text is relative (i.e. does not start with /), then the replaces only the last portion of the path resolved so far - the filename of the symlink itself.

So, if /etc is a symlink to "private/etc" (as it is in OS X), and you copied /etc to /other/place using ditto, then revolving "/other/place/etc" would replace just the "etc" part of the path with "private/etc", and look in /other/place/private/etc, which may or may not exist.

If on the other hand, /etc was a symlink to "/private/etc" then resolving "/other/place/etc" would result in "/private/etc" replacing the entire path resolved so far, so it would end up pointing to the same place.
 
Yeah scruffy I had a feeling it just copied the link file without following, but I wanted some reassurance.

Never be afraid to explain what one may already know... :p Thanks!
 
Back
Top