1、索引点“inode”
——————————————————————————————————————————————
  Linux不是使用文件名来引用文件的,它使用inode。Linux为每个文件分配一个称为索引节点的号码inode,可以将inode简单理解成一个指针,它永远指向文件的具体存储位置。不同文件系统里的inode可以相同。
 
[root@redhat9server root]# ls -il /var
total 64
 114798 drwxr-xr-x    4 root     root         4096 Jul 13 23:26 cache
 164045 lrwxrwxrwx    1 root     root           10 Oct 29  2008 mail -> spool/mail

114798 索引点


2、硬软链接
 ————————————————————————————————————————————
 链接起到一个指向地址的作用(指向原文件)
 链接有两种方式,软链接和硬链接。
 
(1)硬连接
    硬链接不能跨越文件系统(物理区间里面),并且用于链接的文件与源文件完全一样,具有相同的inode值。建硬连接的命令:
 
   ln file_name link_name
  
   在home中建一个新文件original-file 
[root@redhat9server root]# cd /home
[root@redhat9server home]# ls
backup  stud0201  stud0202
[root@redhat9server home]# touch original-file

   查看home中的文件inode
[root@redhat9server home]# ls -il
total 12
 165107 drwxr-xr-x    2 root     root         4096 Jul 16 15:06 backup
 366459 -rw-r--r--    1 root     root            0 Jul 19 06:39 original-file
 165004 drwx------    2 stud0201 class02      4096 Jul 16 15:20 stud0201
 165110 drwx------    2 stud0202 class02      4096 Jul 16 15:58 stud0202

  建硬连接
[root@redhat9server home]# ln original-file hard_link
[root@redhat9server home]# ls -il
total 12
 165107 drwxr-xr-x    2 root     root         4096 Jul 16 15:06 backup
 366459 -rw-r--r--    2 root     root            0 Jul 19 06:39 hard_link
 366459 -rw-r--r--    2 root     root            0 Jul 19 06:39 original-file
 165004 drwx------    2 stud0201 class02      4096 Jul 16 15:20 stud0201
 165110 drwx------    2 stud0202 class02      4096 Jul 16 15:58 stud0202


(2)软链接(符号链接)
   软链接又叫符号链接,这个文件包含了另一个文件的路径名。软链接可跨越文件系统,甚至是不同的计算机系统。文件所得到的inode值是惟一的。软链接文件有点类似于Windows的快捷方式。它实际上是特殊文件的一种。在符号连接中,文件实际上是一个文本文件,其中包含的有另一文件的位置信息。

 
 建软链接
[root@redhat9server home]# ln -s original_file soft_file
[root@redhat9server home]# ls -il
total 12
 165107 drwxr-xr-x    2 root     root         4096 Jul 16 15:06 backup
 366459 -rw-r--r--    2 root     root            0 Jul 19 06:39 hard_link
 366459 -rw-r--r--    2 root     root            0 Jul 19 06:39 original-file
 366460 lrwxrwxrwx    1 root     root           13 Jul 19 06:54 soft_file -> original_file
 165004 drwx------    2 stud0201 class02      4096 Jul 16 15:20 stud0201
 165110 drwx------    2 stud0202 class02      4096 Jul 16 15:58 stud0202

 
3、区别
————————————————————————————————————————— 
   软链接是另一个文件,作用可以理解为一个指针,作用在这个文件上的操作除了删除都直接转向实际指向文件,由于是一个真实的文件所以占用磁盘空间
硬链接可以认为不是一个文件,它只是实际文件的一个别名,它的作用是防止真实文件被误操作,给一个文件建立硬链接后,他们互为别名,删除其中任意一个,只会删除该别名,实际文件并不会被删除。由于只是别名没有任何其他信息,所以并不占用原始文件大小的磁盘空间。


4、验证
(1)修改原文件内容
[root@redhat9server home]# echo "this text goes to the original_file">>original-file
[root@redhat9server home]# ls -il
total 20
 165107 drwxr-xr-x    2 root     root         4096 Jul 16 15:06 backup
 366459 -rw-r--r--    2 root     root           36 Jul 19 07:02 hard_link
 366459 -rw-r--r--    2 root     root           36 Jul 19 07:02 original-file
 366460 lrwxrwxrwx    1 root     root           13 Jul 19 06:54 soft_file -> original_file
 165004 drwx------    2 stud0201 class02      4096 Jul 16 15:20 stud0201
 165110 drwx------    2 stud0202 class02      4096 Jul 16 15:58 stud0202
 
 查看三个文件夹
[root@redhat9server home]# cat original-file
this text goes to the original_file
[root@redhat9server home]# cat hard_link
this text goes to the original_file
[root@redhat9server home]# cat soft_file
this text goes to the original_file

(2)修改原文件名
[root@redhat9server home]# mv original-file original-file123
[root@redhat9server home]# cat hard_link
this text goes to the original_file
[root@redhat9server home]# cat soft_file
cat: soft_file: No such file or directory