linux查看硬鏈接對應的所有文件
阿新 • • 發佈:2017-11-17
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 ~]#
註意:軟鏈接能夠跨越文件系統(分區),硬鏈接不可以。
本文出自 “夜色” 博客,請務必保留此出處http://liuqun.blog.51cto.com/3544993/1982654
linux查看硬鏈接對應的所有文件