Linux服务器编程之:link()函数,ln命令,symlink,readlink,案例说明

50 篇文章 1 订阅
  • 1 link()依赖头文件

#include<unistd.h>

  • 2函数定义

int link(const char *oldpath,const char *newpath);

函数说明:

link() creates a new link (also known as a hard link) to an existing file.
翻译:link()函数为一个已经存在的文件创建一个新的链接(也就是通常所说的“硬链接”)

If newpath exists it will not be overwritten.
翻译:如果新文件已经存在,它将不会被重写

This new name may be used exactly as the old one for any operation;both names refer to the same file (and so have the same permissions and ownership) and it is impossible to tell which name was the “original”.
翻译:新的名字可以替代旧的名字做任何操作,这些名字都指向同一个文(并且也有相同的权限和拥有者),并且很难辨别哪个名称是原始的名称

  • 3.返回值

    一旦成功,返回0,一旦错误,返回-1。并且erron被设置了结果

  • 4.案例说明:
    在这里插入图片描述
    在这里插入图片描述

  • 5.ln命令

说明A:链接有两种,一种被称为硬链接(Hard Link),另外一种被称为符号链接(Symbol link),也叫软链接。建立硬链接时,链接文件和被链接文件必须位于同一个文件系统中,并且不能建立指向目录的硬链接。而对于符号链接,则不存在这个问题。默认情况下,ln产生硬链接。
在这里插入图片描述

  • 6.symlink依赖的头文件

#include<unistd.h>

函数定义:

int symlink(const char *oldpath, const char *newpath);

描述:

symlink() creates a symbolic link named newpath which contains the string oldpath.

  • 7.readlink

读符号链接所指向的文件名字,不读文件内容

ssize_t readlink(const char *path, char *buf, size_t bufsiz)

作者:Jarry_le
来源:CSDN
原文:Linux服务器编程之:link()函数,ln命令,symlink,readlink,案例说明

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值