在 OS X 中创建一个目录的硬链接的 Unix 命令是什么? [英] What is the Unix command to create a hardlink to a directory in OS X?

查看:26
本文介绍了在 OS X 中创建一个目录的硬链接的 Unix 命令是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 OS X 中创建指向目录的硬链接(而不是符号链接或 Mac OS 别名)?我已经知道命令ln target destination",但只有当目标是文件时才有效.我知道 Mac OS 与其他 Unix 环境不同,确实允许硬链接到文件夹(例如,这用于 Time Machine),但我不知道如何自己做.

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 only works when the target is a file. I know that Mac OS, unlike other Unix environments, does allow hardlinking to folders (this is used for Time Machine, for example) but I don't know how to do it myself.

推荐答案

那你就不能直接在 BASH 里搞了.但是......我在这里找到了一篇讨论如何间接做到这一点的文章:http://www.mactech.com/articles/mactech/Vol.23/23.11/ExploringLeopardwithDTrace/index.html 通过编译一个简单的小 C 程序:

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;
}

...并在 Terminal.app 中构建:

...and build in Terminal.app with:

$ gcc -o hlink hlink.c -Wall

这篇关于在 OS X 中创建一个目录的硬链接的 Unix 命令是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆