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

前端 未结 14 1394
天涯浪人
天涯浪人 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 05:47

    In Linux you can use bind mount to simulate hard linking directories. Not sure about OSX

    sudo mount --bind /some/existing_real_contents /else/dummy_but_existing_directory
    sudo umount /else/dummy_but_existing_directory
    
    0 讨论(0)
  • 2020-12-02 05:52

    in case there is no sub folder, you can try

    ln folder_path/*.* target_folder

    it worked for me on OSX 10.9

    0 讨论(0)
  • 2020-12-02 05:55

    Another solution is to use bindfs https://code.google.com/p/bindfs/ which is installable via port:

    sudo port install bindfs
    sudo bindfs ~/source_dir ~/target_dir
    
    0 讨论(0)
  • 2020-12-02 05:59

    Yes it's supported by the kernel and the filesystem, but since it's not intended for general usage it's not exposed to the shell.

    You could probably work out which APIs Time Machine uses and wrap them in a commandline tool, but it'd be better to take the hint and steer well-clear.

    0 讨论(0)
  • 2020-12-02 05:59

    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

    0 讨论(0)
  • 2020-12-02 06:00

    Cross-posting this great tool which neatly solves the problem, originally posted by Sam:


    To install Hardlink, ensure you've installed homebrew, then run:

    brew install hardlink-osx
    

    Once installed, create a hard link with:

    hln [source] [destination]
    

    I also noticed that unlink command does not work on snow leopard, so I added an option to unlink:

    hln -u destination
    

    Code is available on Github for those who are interested: https://github.com/selkhateeb/hardlink

    0 讨论(0)
提交回复
热议问题