What is the Unix command to create a hardlink to a directory in OS X?

前端 未结 14 1448
天涯浪人
天涯浪人 2020-12-02 05:32

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 on

14条回答
  •  佛祖请我去吃肉
    2020-12-02 06:06

    The OSX version of ln cannot do it, but, as mentioned in the other answer by rich, it is possible with the GNU version of ln which is available in homebrew as gln as part of the coreutils formula. man gln lists the -d option with the OSX-specific warning provided in rich's answer. In other words, it does not work in all cases. What exactly determines whether it works or not does not seem to be documented anywhere.

    As a prerequisite, install coreutils:

        brew install coreutils
    

    Now you can do:

        sudo gln -d /original_folder /mirror_folder
    

    IMPORTANT: To remove the hard link you must use gunlink:

        sudo gunlink /mirror_folder
    

    ❗️❗️❗️ Using rm or Finder will also delete the original folder.

    FYI: The coreutils homebrew formula provides the GNU-compatible versions of generic unix tools. Use brew list coreutils to see the full list.

提交回复
热议问题