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

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

    The short answer is you can't. :) (except possibly as root, when it would be more accurate to say you shouldn't.)

    Unixes only allow a set number of links to directories - ".." from within all its children and "." from within itself. Anything else is potentially a recipe for a very confused directory tree. This is/was apparently a design decision by Ken Thompson.

    (Having said that, apparently Apple's Time Machine does do this :) )

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

    You can't do it directly in BASH then. However... I found an article here that discusses how to do it indirectly: http://www.mactech.com/articles/mactech/Vol.23/23.11/ExploringLeopardwithDTrace/index.html by compiling a simple little C program:

    #include <unistd.h>
    #include <stdio.h>
    
    int main(int argc, char *argv[])
    {
       if (argc != 3) return 1;
    
       int ret = link(argv[1], argv[2]);
    
       if (ret != 0) perror("link");
    
       return ret;
    }
    

    ...and build in Terminal.app with:

    $ gcc -o hlink hlink.c -Wall
    
    0 讨论(0)
提交回复
热议问题