linux查看硬链接对应的所有文件

简介:

在linux中,链接文件分为硬链接和软链接文件两种,其中硬链接通过ln source_file dist_file建立,软链接通过ln -s source_file dist_file建立。

软硬链接的区别:硬链接相当于一个文件两个名称,而软链接相当于创建指向源的快捷方式

注意:源文件是已经存在的文件,目标文件是要创建的文件

软链接实验:

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@openstack ~] # ll
总用量 22024
-rw-------.  1 root root     1311 9月  29 04:14 anaconda-ks.cfg
drwxr-xr-x. 18  501  501     4096 10月 30 21:29 Python-3.6.1
-rw-r--r--.  1 root root 22540566 3月  21 2017 Python-3.6.1.tgz
[root@openstack ~] # ln -s anaconda-ks.cfg anaconda-ks.cfg.ln 
[root@openstack ~] # ll
总用量 22024
-rw-------.  1 root root     1311 9月  29 04:14 anaconda-ks.cfg
lrwxrwxrwx.  1 root root       15 11月 16 23:13 anaconda-ks.cfg. ln  -> anaconda-ks.cfg
drwxr-xr-x. 18  501  501     4096 10月 30 21:29 Python-3.6.1
-rw-r--r--.  1 root root 22540566 3月  21 2017 Python-3.6.1.tgz
[root@openstack ~] #

软链接可以通过ls -l命令看了软链接文件,标识是-> 表示目标指向源文件,跟ln定义的时候相反。

硬链接实验:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@openstack ~] # ll
总用量 22024
-rw-------.  1 root root     1311 9月  29 04:14 anaconda-ks.cfg
lrwxrwxrwx.  1 root root       15 11月 16 23:13 anaconda-ks.cfg. ln  -> anaconda-ks.cfg
drwxr-xr-x. 18  501  501     4096 10月 30 21:29 Python-3.6.1
-rw-r--r--.  1 root root 22540566 3月  21 2017 Python-3.6.1.tgz
[root@openstack ~] # ln anaconda-ks.cfg anaconda-ks.cfg.hln
[root@openstack ~] # ls -l
总用量 22028
-rw-------.  2 root root     1311 9月  29 04:14 anaconda-ks.cfg
-rw-------.  2 root root     1311 9月  29 04:14 anaconda-ks.cfg.hln
lrwxrwxrwx.  1 root root       15 11月 16 23:13 anaconda-ks.cfg. ln  -> anaconda-ks.cfg
drwxr-xr-x. 18  501  501     4096 10月 30 21:29 Python-3.6.1
-rw-r--r--.  1 root root 22540566 3月  21 2017 Python-3.6.1.tgz
[root@openstack ~] #

可以看到不能通过ls -l看到anaconda-ks.cfg的硬链接指向哪个文件,只能看到硬链接计数变成了2.

我们可以通过inode来找到anaconda-ks.cfg的另外一个硬链接文件。

1
2
3
4
5
6
7
8
9
10
11
root@openstack ~] # ls -il
总用量 22028
33582147 -rw-------.  2 root root     1311 9月  29 04:14 anaconda-ks.cfg
33582147 -rw-------.  2 root root     1311 9月  29 04:14 anaconda-ks.cfg.hln
33582167 lrwxrwxrwx.  1 root root       15 11月 16 23:13 anaconda-ks.cfg. ln  -> anaconda-ks.cfg
50716171 drwxr-xr-x. 18  501  501     4096 10月 30 21:29 Python-3.6.1
34101767 -rw-r--r--.  1 root root 22540566 3月  21 2017 Python-3.6.1.tgz
[root@openstack ~] # find / -inum 33582147
/root/anaconda-ks .cfg
/root/anaconda-ks .cfg.hln
[root@openstack ~] #

注意:软链接能够跨越文件系统(分区),硬链接不可以。














本文转自lq201151CTO博客,原文链接:http://blog.51cto.com/liuqun/1982654 ,如需转载请自行联系原作者


相关文章
|
15天前
|
Linux Shell
Linux手动清理Linux脚本日志定时清理日志和log文件执行表达式
Linux手动清理Linux脚本日志定时清理日志和log文件执行表达式
70 1
|
19天前
|
Linux 数据安全/隐私保护 Windows
Linux入门指南:linux权限究竟是什么?和文件有什么关系?
Linux入门指南:linux权限究竟是什么?和文件有什么关系?
30 0
|
14天前
|
人工智能 安全 Linux
【Linux】Linux之间如何互传文件(详细讲解)
【Linux】Linux之间如何互传文件(详细讲解)
|
1天前
|
Linux 内存技术 Perl
【ZYNQ】制作从 QSPI Flash 启动 Linux 的启动文件
【ZYNQ】制作从 QSPI Flash 启动 Linux 的启动文件
|
7天前
|
Linux 索引
linux 文件查找 和文件管理常用命令
linux 文件查找 和文件管理常用命令
17 0
|
9天前
|
监控 Linux
|
14天前
|
存储 Ubuntu Linux
制作一个嵌入式Linux的应用程序升级文件
制作一个嵌入式Linux的应用程序升级文件
12 2
|
15天前
|
Linux Shell
Linux脚本获取输入参数判断文件还是文件路径
Linux脚本获取输入参数判断文件还是文件路径
12 4
|
15天前
|
Linux
linux无法删除文件的时候先看看文件属性
linux无法删除文件的时候先看看文件属性
23 2
|
15天前
|
Linux Shell 开发工具
linux编辑文件出现write.error.(file.system.full?)
linux编辑文件出现write.error.(file.system.full?)
10 1