1. 命令功能

ln 可以看做是link的简写,功能是创建链接文件,链接文件包括硬链接(hard link)和软链接(符号链接,symbolic link)

2. 语法格式

ln  [option]  source  target

ln  选项  源文件或目录  目标文件或目录

参数

参数说明

无选项

创建硬链接

-s

创建软链接(符号链接)

目录没有硬链接,只有软链接。

3. 硬软链接文件知识

1. 硬链接

硬链接文件创建方式:ln 源文件  目标文件

每个文件都有一个inode(索引)节点,这个inode就是指向文件在磁盘中具体存放的位置编号。创建硬链接,就是在创建一个文件名,这个文件名指向同一个inode索引,相当于给文件的另一个入口。例如到一个房子开始只有一个门能进入,现在又开了另一个门当做出口。这样做的好处,例如备份文件,删除源文件,只是把源文件名删除了,还可以通过硬链接文件访问这个文件,放置误删除。

硬链接的特性:

  1. 具有相同inode节点的多个文件互为硬链接。
  2. 删除源文件或硬链接文件其中之一,文件实体没有被删除。
  3. 只有删除源文件及全部硬链接文件后,文件实体才会被删除。
  4. 可以给文件设置硬链接,来防止重要文件被误删。
  5. 硬链接可以用rm命令删除。
  6. ls –lih 查看第三列,即硬链接数。
  7. 对于静态文件(文件没有被调用),当对应的硬链接数为0时,文件就会被删除

实例:创建硬链接

[root@localhost DIR]# ln 123 abc

[root@localhost DIR]# ls -l

total 0

-rw-r--r--. 2 root root 0 Mar 13 23:21 123

-rw-r--r--. 2 root root 0 Mar 13 23:21 abc    #abc是123的硬链接文件

[root@localhost DIR]# ls –lih

total 0

786446 -rw-r--r--. 2 root root 0 Mar 13 23:21 123  #inode号相同;2 表示有硬链接数:3

786446 -rw-r--r--. 2 root root 0 Mar 13 23:21 abc

[root@localhost DIR]# ln 123 def

[root@localhost DIR]# ls -lih

total 0

786446 -rw-r--r--. 3 root root 0 Mar 13 23:21 123  # 硬链接数有3

786446 -rw-r--r--. 3 root root 0 Mar 13 23:21 abc

786446 -rw-r--r--. 3 root root 0 Mar 13 23:21 def

[root@localhost DIR]# ls -lih 123

786446 -rw-r--r--. 3 root root 0 Mar 13 23:21 123

2. 软链接

软链接(符号链接),类似windows中的快捷方式。

软链接创建方式:ln –s 源文件 目标文件

[root@localhost home]# ls -l test.txt

-rw-r--r--. 1 root root 27 Mar 14 22:45 test.txt

[root@localhost home]# ln -s test.txt test.txt_link   #创建软链接

[root@localhost home]# ls -l test.txt test.txt_link

-rw-r--r--. 1 root root 27 Mar 14 22:45 test.txt

lrwxrwxrwx. 1 root root  8 Mar 14 22:45 test.txt_link -> test.txt  #l:软链接标识符

软链接文件和源文件的inode号不一样,链接数也不一样

[root@localhost home]# ls -lih test.txt test.txt_link

786434 -rw-r--r--. 1 root root 27 Mar 14 22:45 test.txt

786448 lrwxrwxrwx. 1 root root  8 Mar 14 22:45 test.txt_link -> test.txt

最新文章

  1. [WCF编程]11.错误:错误类型
  2. Java多线程系列--“JUC原子类”04之 AtomicReference原子类
  3. 初学git,出现错误:fatal: Not a git repository (or any of the parent directories): .git
  4. Android两个独立的应用跳转实现方式小结
  5. Go语言interface详解
  6. gridView使用
  7. 牛场围栏(vijos 1054)
  8. 海外支付:抵御信用卡欺诈的CyberSource
  9. 针对《来用》的NABC分析
  10. (转)使用Amoeba 实现MySQL DB 读写分离
  11. linux jps 命令
  12. 写给新手看的Flask+uwsgi+Nginx+Ubuntu部署教程
  13. 个人信用卡管理 - iOS UI原型
  14. URAL 1225 Flags
  15. koa+mysql+vue+socket.io全栈开发之数据访问篇
  16. php获取父目录的方法 dirname()
  17. [IOI 2000]POJ 1160 Post Office
  18. HDU - 2892:area (圆与多边形交 求面积)
  19. 转载:centos安装redis
  20. 1926: [Sdoi2010]粟粟的书架

热门文章

  1. XXX is not a function
  2. Spring Cloud架构教程 (八)消息驱动的微服务(消费组)【Dalston版】
  3. wap开发tips
  4. db2用户权限赋值
  5. 线性代数之——SVD 分解
  6. 【C++进阶:STL常见性质】
  7. spring集成mongodb通过aop记录业务日志
  8. 像计算机科学家一样思考python-第3章 函数
  9. 非web工程,打jar放shell执行
  10. 009-Spring Boot 事件监听、监听器配置与方式、spring、Spring boot内置事件