Can I hard link files with rsync instead of copying them?

cp -l hard links files instead of copying them, saving filesystem space. I need to use rsync instead of cp because of its --exclude capabilities.

So my question is, how do I get rsync to hard link files instead of copying them? Obviously, this is a local filesystem copy. I've read the docs for rsync's -H option, but it's unclear to me if this behaves the same way as cp -l.

4

2 Answers

The answer has turned out to be yes, with rsync's --link-dest option. It's just not obvious because it's not a simple on/off flag like cp -l, because it takes a path argument.

So, cp -l a/ b/ can also be done like this:

rsync -a --link-dest=a a/ b/
2

I've been using for a long time. It does exactly what you are describing.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like