1

软硬方式链接_微笑涛声的技术博客_51CTO博客

 1 year ago
source link: https://blog.51cto.com/u_14068620/5754940
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

软硬方式链接

精选 原创

微笑涛声 2022-10-14 07:44:09 博主文章分类:Linux系统 ©著作权

文章标签 硬链接 符号链接 软链接 文章分类 软考 考试认证 yyds干货盘点 阅读数210

在 Linux 系统中的 ln 命令能够让用户创建出两种不同类型的文件快捷方式,一定要注意区分:

硬链接 (hard link) 可以被理解为一个 “ 指向原始文件 inode 的指针 ” ,系统不为它分配独立的 inode
与文件,所以实际上来讲硬链接文件与原始文件其实是同一个文件,只是名字不同。于是每添加一个硬链接,
该文件的 inode 连接数就会增加 1 ,直到该文件的 inode 连接数归 0 才是彻底删除。概括来说因为硬链
接实际就是指向原文件 inode 的指针,即便原始文件被删除依然可以通过链接文件访问,但是不能跨文件
系统也不能链接目录文件。

软链接也称为符号链接( symbolic link )即 “ 仅仅包含它索要链接文件的路径名 ” 因此能做目录链接也
可以跨越文件系统,但原始文件被删除后链接文件也将失效,如同 WinodwTM 中的 “ 快捷方式 ” 。

ln 命令用于创建链接文件,格式为: “ ln [ 选项 ] 目标 ” 。

  • 创建硬链接 :“ln 文件名 链接名 ”
  • 创建软链接 :“ln -s 文件名 连接名 ”
参数 作用
-s 创建"符号链接"(默认是硬链接)
-f 强制创建文件或目录的链接
-i 覆盖前先询问
-v 显示创建链接的过程
[root@rhel7 tmp]# echo this is a > file
[root@rhel7 tmp]# cat file
this is a
[root@rhel7 tmp]# ll file
-rw-r--r--. 1 root root 10 Jun 22 16:02 file
[root@rhel7 tmp]# ln file fileh
[root@rhel7 tmp]# ll file fileh
[root@rhel7 tmp]# ll file fileh files -i
52973928 -rw-r--r--. 2 root root 10 Jun 22 16:02 file
52973928 -rw-r--r--. 2 root root 10 Jun 22 16:02 fileh
52973930 lrwxrwxrwx. 1 root root 4 Jun 22 16:03 files -> filefile
软硬方式链接_软链接

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK