1先看man对他的解释

2函数
man 2 link
• 硬链接函数
• int link(const char oldpath, const char newpath);
– 参数oldpath:已有的文件路径。
– 参数newpath:新建的硬链接文件路径。
– 返回值:成功返回0,错误返回-1。
3测试代码
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
int main(int argv,char*argc[])
{
printf("pls input file or content path and want change path\n");
if(argv<3)
{
printf("need 3 para \n");
exit(1);
}
if(0!=link(argc[1],argc[2]))
{
printf("chg err \n");
}else
{
printf("chg success \n");
}
return 0;
}
4终端测试 123 和 888内容 inod 一致

网友评论