1

I want to duplicate directory 'foo' and all its subdirectories to 'foo_copy'.

1) I don't want 'foo_copy' to have several copies of some files or directories with one copy for each symlink to the file or directories.

2) I don't want 'foo_copy's symlinks to point back to the 'foo' directory.

I want an exact duplicate with:

1) 'foo_copy's files and directories residing in the same place as they did in 'foo' except now in 'foo_copy'.

2) 'foo_copy's symlinks pointing to the same files or directories they had pointed to in 'foo' except now in 'foo_copy'.

I don't know if my links are absolute or relative. I'm hoping for a solution that would work either way.

Bonus points, this is for Mac (FreeBSD) with rsync version 2.6.9 protocol version 29.

  • Are your existing symlinks absolute or relative? – roaima Dec 8 '17 at 18:17
  • What version of rsync do you have? – roaima Dec 8 '17 at 18:21
  • I have rsync version 2.6.9 protocol version 29. I don't know if my links are absolute or relative. I'm hoping for a solution that would work either way. – Joe C Dec 10 '17 at 0:06
3

Some alternatives to cp (which I am going to assume someone will answer with the BSD version of) are the standard POSIX utility pax:

$ cd foo
$ install -d ../foo_copy
$ pax -r -w -p p * ../foo_copy/

Apple's ditto:

$ ditto foo foo_copy

the tool that you asked about, which has some subtle gotchas, but fortunately the only one that you will hit here is the necessity to use trailing slashes:

$ rsync --archive --hard-links --extended-attributes foo/ foo_copy/

and of course the duplicate function (⌘ Super+D) in the Finder.

Further reading

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.