1. 查看 unlink 在帮助手册中的说明:
unlink() deletes  a name from the filesystem. If that name was the last link to a file and no processes have the file open the file is deleted and the space it was using is made available for reuse.
If the name was the last link to a file but any processes still have the file open the file will remain in existence until the last file descriptor referring to it is closed.
    根据描述,unlink 会删除文件名,并减少连接数。如果是最后一个连接并且没有进程打开文件,文件将会被删除,并释放空间。如果是最后一个连接但是有进程打开文件,文件仍会存在,直到打开的文件被关闭。
    现在看一个例子:
    [root@localhost tmp]# echo "hello" > a.txt
[root@localhost tmp]# ln a.txt a.txt.ln  # 创建一个硬连接,a.txt和a.txt.ln指向的是相同的磁盘内容
    [root@localhost tmp]# ll
total 40
-rw-r--r-- 2 root root    6 Feb 26 13:21 a.txt
-rw-r--r-- 2 root root    6 Feb 26 13:21 a.txt.ln
-rw-r--r-- 1 root root  511 Dec 22 10:15 device.info
drwxr-xr-x 2 root root 4096 Jul 25  2016 vmware-root
drwx------ 2 root root 4096 Jul 25  2016 vmware-root-2117350667
[root@localhost tmp]# 
现在a.txt和a.txt.ln的连接数都是2(ll命令显示的第二列表示连接数),下面用unlink命令删除a.txt(unlink命令是直接调用unlink函数来实现的)
[root@localhost tmp]# unlink a.txt
[root@localhost tmp]# ll 
total 32
-rw-r--r-- 1 root root    6 Feb 26 13:21 a.txt.ln
-rw-r--r-- 1 root root  511 Dec 22 10:15 device.info
drwxr-xr-x 2 root root 4096 Jul 25  2016 vmware-root
drwx------ 2 root root 4096 Jul 25  2016 vmware-root-2117350667
[root@localhost tmp]# 
现在a.txt被删除了,同时a.txt.ln的连接数变成了1。说明unlink会删除文件名,并减少连接数。但是a.txt占用的磁盘空间还是存在的,需要a.txt.ln被删除后,占用的空间才会被释放。
2. 查看 remove 在帮助手册中的说明:
remove() deletes a name from the filesystem.  It calls unlink() for files, and rmdir() for directories.
If the removed name was the last link to a file and no processes have the file open the file is deleted and the space it was using is made available for reuse.
If  the name was the last link to a file but any processes still have the file open the file will remain in existence until the last file descriptor referring to it
is closed.
        通过描述,可以看出在remove比unlink多了个删除目录的功能,在删除文件时,remove和unlink的功能是一样的。

unlink函数 与 remove函数相关推荐

  1. python中remove函数是什么意思,python中pop函数和remove函数有什么区别

    python中pop函数和remove函数有什么区别 发布时间:2020-12-10 09:36:18 来源:亿速云 阅读:80 作者:小新 小编给大家分享一下python中pop函数和remove函 ...

  2. Python 使用del函数和remove函数注意点

    最近在写项目中使用到del函数和remove函数,出现了一些常识性但又容易忘记的错误,在这里记录一些,也是给自己提醒一下. 首先,del和remove的区别,很好理解. del:利用del[索引数] ...

  3. Java知识点06:队列(Queue)的offer/add函数,poll/remove函数,peek/element函数的区别

    一.Queue接口的描述 Queue接口,实现了 Collection接口. 队列是一种特殊的线性表,它只允许在表的前端进行删除操作,而在表的后端进行插入操作. 在Queue中,有 offer.add ...

  4. linux下remove函数

    remove(删除文件) 相关函数 link,rename,unlink 表头文件 #include<stdio.h> 定义函数 int remove(const char * pathn ...

  5. R语言使用fs包的dir_delete函数删除指定的文件目录(remove the directory)、举一反三、file_delete函数、link_delete函数可以用来删除文件和文件夹

    R语言使用fs包的dir_delete函数删除指定的文件目录(remove the directory).举一反三.file_delete函数.link_delete函数可以用来删除文件和文件夹 目录

  6. R语言应用substr函数和substring函数抽取(extract)、删除(Remove)、替换、匹配(Match)特定的字符串、并对比两个函数的异同、grepl检查子字符串是否存在于字符串中

    R语言应用substr函数和substring函数抽取(extract).删除(Remove).替换(Replace).匹配(Match)特定的字符串.并对比substr函数和substring函数在 ...

  7. STL的remove函数和list的remove成员函数

    今天看书刚刚看的,就记录下来吧.这可能是老生常谈了,权且作为一个警醒的例子吧. 大家都知道STL有两个非常重要的组成部分,容器和算法. 算法就是一个个的函数,通过迭代器和容器关联在一起,完成一些工作. ...

  8. 42、Power Query-Text.Remove函数应用

    本节我们学习函数:Text.Remove Removes all occurrences of a character or list of characters from a text value. ...

  9. python remove函数_python中remove函数的用法是什么?

    python中remove函数的用法是什么? python中remove函数的用法: 描述 remove() 函数用于移除列表中某个值的第一个匹配项. 语法 remove()方法语法: list.re ...

  10. python 列表 remove()函数使用详解

    「作者主页」:士别三日wyx remove函数使用详解 1. 基本使用 2. 删除普通类型元素 3. 删除对象类型元素 4. 一次只删一个元素 1. 基本使用 remove() 函数可以删除列表中的指 ...

最新文章

  1. mysql 查询结果转置_转置MySQL查询 – 需要将行放入列中
  2. 变态题大串烧:微软面试问题 -- 三.难题:这类题有一定难度,如果得不到答案,也不能说明什么...
  3. python 切割字符串
  4. html设置input圆角矩形_如何选择绘画尺寸、认识快捷键和设置快捷键
  5. SAP 电商云 Spartacus UI set delivery mode HTTP put 请求的触发时机
  6. 关于快速开发和设计应用系统的一些个人的意见
  7. 程序员面试金典 - 面试题 17.15. 最长单词(排序+递归)
  8. Intellij IDEA 14 安装之后
  9. 矩池云上缺少cusparse.h头文件解决方法
  10. python time
  11. 分享40个主机域名PHP源码,总有一款适合你
  12. 【高清视频压制教程】使用MeGUI压制视频教程(以PSP视频为例)(转载)
  13. WINDOWS超级热键
  14. 使用bootstrap图片上传插件(fileInput)springmvc实现图片上传全流程
  15. 数字基建系列(一)数分如何参与埋点工作
  16. 微信小程序左滑删除(Slideview)
  17. Go语言150行代码搞定苹果Apns高并发推送
  18. Codeforces Round #578 (Div. 2) 题解报告
  19. CrossFire和SLI
  20. 华为p10关闭更新_华为P10正常升级和强制降级详细方法

热门文章

  1. 1.4 数列极限概念的推广
  2. html新建站点的操作步骤,如何在服务器上建立站点的方法步骤
  3. 计算机edp测试是什么测试,五、信息工具--(一)EDP:电子数据处理
  4. 人活着到底为了什么?
  5. 【数据集】人工智能领域比较常见的数据集汇总
  6. macbook更新系统服务器,为Mac新系统做准备 苹果更新OSX Server
  7. Java初学者日志_05
  8. 什么是测试场景标准库?
  9. 台式计算机主机内置喇叭不响,台式机扬声器没声音怎么样解决
  10. 英语在线教育机构争战AI风口,为何雷声大雨点小?