What is the Unix command to create a hardlink to a

2019-01-10 02:30发布

How do you create a hardlink (as opposed to a symlink or a Mac OS alias) in OS X that points to a directory? I already know the command "ln target destination" but that only works when the target is a file. I know that Mac OS, unlike other Unix environments, does allow hardlinking to folders (this is used for Time Machine, for example) but I don't know how to do it myself.

14条回答
我欲成王,谁敢阻挡
2楼-- · 2019-01-10 03:24

As of 2018 no longer possible. APFS (introduced in MacOS High Sierra 10.13) is not compatible with directory hardlinks. See https://github.com/selkhateeb/hardlink/issues/31

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-01-10 03:25

This can also be done with built-in Perl (from Terminal) without compiling anything. My specific use case is for Google Drive (which doesn't support symbolic links), so the examples below reflect the use case.

To link your "Documents" folder to Google Drive so it's synced:

perl -e 'link "/Users/me/Documents", "/Users/me/Google Drive/Documents"'

To remove the link to your "Documents" folder from Google Drive:

sudo perl -U -e 'unlink "/Users/me/Google Drive/Documents"'

You need "root" to unlink (see "unlink" perldoc).

查看更多
登录 后发表回答