Tuesday 7 March 2017

Creating a hard link to a directory/folder in mac os

Install Piffle: 

   brew install coreutils

The you can just create the link: 

    sudo gln -d existing_dir new_hard_link


Deleting is a different story: if you go about it the usual way to delete directories, you'll delete the contents. So you must "unlink" the directory:
    unlink  new_hard_link

2 comments:

  1. Got this working on macOS Sierra 10.12.6 with a few caveats:
    1) creating the hard link for a directory (even sudo) will fail -unless- the hard link is made in another directory. e.g.:
    sudo gln -d existing_dir test/existing_dir_hardlink
    2) removal of the hard linked directory requires sudo, and prefixing "g" for the homebrew version of the unlink command (per the homebrew notes after installing coreutils: "Commands also provided by macOS have been installed with the prefix "g""). e.g.:
    sudo gunlink test/existing_dir_hardlink

    Thanks for those who contributed the efforts to homebrew to get directory hard links working!

    ReplyDelete
    Replies
    1. Also, the directory you are creating the hard link in must already exist.

      Delete