Linux: file attribute information - the number of soft and hard links (ln)

File attribute information - number of hard links

Hard Links:

Concept Note: Multiple doors ??? supermarket in a partition, the same file inode number, each other hard links

诞生过程:
ln  链接的源文件    硬链接的文件信息
[root@oldboyedu oldboy]# ln /oldboy/oldboy.txt /oldboy/oldboy_hard_link.txt 
[root@oldboyedu oldboy]# ll
total 8
-rw-r--r--. 2 root root 13 Apr 16 10:49 oldboy_hard_link.txt
-rw-r--r--. 2 root root 13 Apr 16 10:49 oldboy.txt
Use the find command to find more than a hard-linked files
[root@oldboyedu oldboy]# find / -type f -inum 33584339 
/etc/hosts
/tmp/hosts
系统中的目录不能创建硬链接

[root@oldboyedu ~]# ll /etc/|grep -c "^d"
78
[root@oldboyedu ~]# ll /etc/|grep  "^d"|wc -l
78

Soft links:

Concept Note: shortcut file

诞生过程:
ln -s 链接的源文件  软链接的文件信息

[root@oldboyedu oldboy]# ln -s /oldboy/oldboy.txt /oldboy/oldboy_soft_link.txt 
[root@oldboyedu oldboy]# ll
total 8
lrwxrwxrwx. 1 root root 18 Apr 16 10:50 oldboy_soft_link.txt -> /oldboy/oldboy.txt
-rw-r--r--. 2 root root 13 Apr 16 10:49 oldboy.txt

The difference between hard and soft links:

01. 链接后的文件大小不一致
02. 链接后的文件类型和权限不一致(颜色不一致)
03. 链接后的文件和源文件 inode信息有出入
    硬链接inode号码一致
    软链接inode号码不一样
04. 源文件被删除之后
    硬链接文件依然有效
    软链接文件失效
05. 软硬链接创建过程不一致

Guess you like

Origin www.cnblogs.com/moox/p/12179848.html