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

               

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)



           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自blog.csdn.net/jdtugfcg/article/details/86524599
今日推荐