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

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

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

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

软链接实验:

[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定义的时候相反。

硬链接实验:

[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的另外一个硬链接文件。

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 ~]#

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值