search

Home  >  Q&A  >  body text

linux中什么命令可以判断硬链接和软链接?

linux中什么命令可以判断硬链接和软链接?
比如,在centos7.2的/etc/systemd/system目录,有一个mysqld.service,图标上有个箭头,但怎么区分这是软链接还是硬链接呢?以及它指向文件的位置怎么查看?
百度了一下,没找到相关答案。

天蓬老师天蓬老师2769 days ago617

reply all(6)I'll reply

  • PHPz

    PHPz2017-04-17 15:20:12


    As shown in the picture above: ls -al shows that the soft link starts with l, and there is a "->" pointer when the file name is displayed.

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 15:20:12

    ls -al You can view the direction of the soft link
    A hard link is equivalent to creating a copy of the file information. It is exactly the same as the original file. There is no difference except the file name. It is just two files. Only one copy of the file pointed to by the name exists on the hard disk. .
    You can refer to soft links and hard links

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 15:20:12

    file is enough, for example:

    eechen@ubuntu:~$ file /usr/bin/vi
    /usr/bin/vi: symbolic link to `/etc/alternatives/vi' 

    reply
    0
  • 阿神

    阿神2017-04-17 15:20:12

    Hard links cannot be judged. The status of the two files before and after them is equal. There is no saying who has the hard link.
    Soft links can be judged using anything,

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 15:20:12

    Soft link As mentioned above, just use ls to view it

    ls -l

    Hard links can be understood like this: copy a file, and this file has a synchronization function. If one of them is deleted, the other one will still exist.

    The i-node number of the hard link and the source file is the same. You can use the following command to view it. However, you cannot distinguish which is the source file and which is the hard link because their status is equal. You can only see This file creates a hard link

    ls -li

    reply
    0
  • 黄舟

    黄舟2017-04-17 15:20:12

    Hard links cannot cross file systems and cannot operate on directories. Multiple files point to the same inode number at the same time.
    Soft links can span file systems and work on directories and files.

    ln a c creates a hard link
    Add data in file a, and the same data will be in file c.

    The a file is deleted, but the c file still exists. Think of hard links as a kind of backup.
    The soft link can be regarded as a reference method and a calling method. The link file itself only stores the path and does not save the data.
    So when the source file is deleted, the soft link file will also become invalid.

    Generally, you can only view soft links through ls -l. At present, it is not possible to check the hard link pointing method, and there is no need to check it, because they can be regarded as mirror images of each other, exactly the same. For related information, you can only see the number of hard links after ls -l.

    reply
    0
  • Cancelreply