Linux view all files corresponding to hard links

Source: Internet
Author: User

In Linux, the link file is divided into hard-link and soft-link file two, where hard links are established through ln source_file dist_file, and soft links are established through Ln-s source_file Dist_file.

The difference between soft and hard links: A hard link is equivalent to a file with two names, and a soft link is equivalent to creating a shortcut to the source

Note: The source file is a file that already exists, and the destination file is the file to be created

Soft link Experiment:

[[email protected] ~]# ll total dosage  22024-rw-------.   1 root root      1311 9 Month   29 04:14 anaconda-ks.cfgdrwxr-xr-x. 18  501   501     4096 10 month  30 21:29 python-3.6.1-rw-r--r--.   1 root root 22540566 3 Month   21 2017 python-3.6.1.tgz[[email  protected] ~]# ln -s anaconda-ks.cfg anaconda-ks.cfg.ln [[email  Protected] ~]# ll Total dosage  22024-rw-------.   1 root root      1311 9 Month   29 04:14 anaconda-ks.cfglrwxrwxrwx.  1 root root        15 11 Month  16 23:13 anaconda-ks.cfg.ln ->  anaconda-ks.cfgdrwxr-xr-x. 18  501  501     4096  October  30 21:29  Python-3.6.1-rw-r--r--.   1 root root 22540566 3 Month   21 2017  python-3.6.1.tgz[[email protected] ~]#

Soft links can be seen through the ls-l command of the soft link file, the identification is the target point to the source file, as defined by LN is the opposite.

Hard-Link experiments:

[[email protected] ~]# ll total dosage  22024-rw-------.   1 root root      1311 9 Month   29 04:14 anaconda-ks.cfglrwxrwxrwx.  1 root  root       15 11 Month  16 23:13 ANACONDA-KS.CFG.LN  -> anaconda-ks.cfgdrwxr-xr-x. 18  501  501      4096 10 Moon  30 21:29 python-3.6.1-rw-r--r--.   1 root root  22540566 3 Month   21 2017 Python-3.6.1.tgz[[email protected] ~]# ln  Anaconda-ks.cfg anaconda-ks.cfg.hln[[email protected] ~]# ls -l Total Dosage  22028- RW-------.   2 root root     1311 9 Month   29 04:14  ANACONDA-KS.CFG-RW-------.   2 root root     1311 9 Month   29 04:14 anaconda-ks.cfg.hlnlrwxrwxrwx.  1 root root       15  November  16 23:13 anaconda-ks.cfg.ln -> anaconda-ks.cfgdrwxr-xr-x. 18   501  501     4096 10 month  30 21:29 python-3.6.1-rw-r--r--.   1 root root 22540566 3 Month   21 2017 python-3.6.1.tgz[[email  protected] ~]#

You can see which file the hard link to anaconda-ks.cfg cannot see through Ls-l , and only see that the hard link count becomes 2.

We can find another hard-link file for anaconda-ks.cfg through the inode.

[Email protected] ~]# ls -il total dosage  2202833582147 -rw-------.   2 root  root     1311 9 Month   29 04:14 anaconda-ks.cfg33582147  -RW-------.   2 root root     1311 9 Month   29  04:14 anaconda-ks.cfg.hln33582167 lrwxrwxrwx.  1 root root        15 11 Month  16 23:13 anaconda-ks.cfg.ln ->  anaconda-ks.cfg50716171 drwxr-xr-x. 18  501  501      4096 10 month  30 21:29 python-3.6.134101767 -rw-r--r--.   1 root root  22540566 3 Month   21 2017 python-3.6.1.tgz[[email protected] ~]# find  / -inum 33582147/root/anaconda-ks.cfg/root/anaconda-ks.cfg.hln[[email protected] ~]#

Note: Soft links can span file systems (partitions) and hard links are not available.

This article is from the "Night" blog, please be sure to keep this source http://liuqun.blog.51cto.com/3544993/1982654

Linux view all files corresponding to hard links

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.