Last active
October 7, 2015 14:13
-
-
Save bao3/8be962381d0c3eae13f9 to your computer and use it in GitHub Desktop.
Mac OS X HardLink c file 苹果系统制作硬链接的命令行工具,原作者是 http://www.cppblog.com/biao/archive/2013/09/09/203123.html 。不过从他那边弄下来后会有错误,因此这里将修正好再托管。 顺道吐槽一下,妈的,google中文资料,一帮傻逼全在讨论 mac 硬连接软链接和替身,竟然都不告诉大家怎么制作硬链接。反而硬链接非常有必要,比如你同时有百度网盘,dropbox,onedrive,硬链接帮你解决需要重复放置同一份文件这个问题。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
#include <stdio.h> | |
// Build: gcc -o hlink hlink.c -Wall | |
int main(int argc, char *argv[]) { | |
printf("Usage: assume the program name is hlink\n"); | |
printf("sudo ./hlink source_directory destination_directory\n"); | |
if (argc != 3) return 1; | |
int ret = link(argv[1], argv[2]); | |
if (ret == 0) { | |
printf("\n"); | |
printf("****** Create hard link successful ******\n"); | |
} else { | |
perror("link"); | |
} | |
return ret; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> /* memset */ | |
#include <unistd.h> /* close */ | |
// Build: gcc -o hunlink hunlink.c | |
int main(int argc, char *argv[]) { | |
printf("Usage: assume the program name is hunlink\n"); | |
printf("sudo ./hunlink destination_directory\n"); | |
if (argc != 2) return 1; | |
int ret = unlink(argv[1]); | |
if (ret == 0) { | |
printf("\n"); | |
printf("****** Delete hard link successful ******\n"); | |
} else { | |
perror("unlink"); | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment