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

前端 未结 14 1400
天涯浪人
天涯浪人 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:03

    Piffle. On 10.5, it tells you in the man page for ln:

       -d, -F, --directory
              allow the superuser to attempt to hard link  directories  (note:
              will  probably  fail  due  to  system restrictions, even for the
              superuser)
    

    So yes:

        sudo  ln  -d  existing_dir  new_hard_link
    

    Give it your password, and you're not done yet. You didn't document it, did you? You must document hard linked directories; even if it's a single user machine.

    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
    

    There. Hope you don't wreck your filesystem!

提交回复
热议问题