硬链接(基于itop4412)

1先看man对他的解释

image.png

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 一致

image.png
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容