Soft and hard-wired connection summary difference, and with the example operation described

Soft link
   ln -s original file destination
   features: 1, the equivalent of shortcuts windows
           2, a symbolic link, the link to the file size is very small
           3, when run soft connection, will point to find links to the real file, and then execute
                   4, all rights linked files are 777, and the real authority by pointing file decided that
                   5, after the original file is missing, soft link does not work, can not find the error will be reported
                   6, ls -al, the source files back arrow to perform a soft connection of
  
a hard link
   ln source destination file
   characteristics: 1, the properties of the original file and link files exactly as
      2, the relationship between the link and source files are similar: + synchronous replication update
      3, when the original file is missing, you can also access the hard-linked files
      4, can not span partitions, you can not use the directory for
      5, principle: the same original file and hard linked files node, a file name can correspond to a node number. However, a node number can correspond to a plurality of file names. So, they are exactly the same attributes, and modify the contents of one another will follow changes.
 
Examples are as follows:
Create a soft link b a file and see a soft and linked files a.link of inodes, permissions, size, as follows:
[root@VM_0_15_centos ~]# ln -s a a.link
[root@VM_0_15_centos ~]# ll -i
total 6728
394681 -rw-r--r-- 1 root root 6888896 Nov 10 21:42 a
394522 lrwxrwxrwx 1 root root       1 Nov 10 21:45 a.link -> a
From the results of the command point of view, the following conclusions:
1, inode number of a file is 394681, a.link inode file is 394522, inode number is inconsistent.
2, a symbolic link, the link to the file size is very small. a.link size 1bit, while the size of a file is 6.6M.
3, all a.link file permissions are 777, and the real authority is determined by the file pointed to
 
 
Delete the file a, file access a.link link
[root@VM_0_15_centos ~]# mv a a.bak
[root@VM_0_15_centos ~]# cat a.link
cat: a.link: No such file or directory
Summary: After the original file is missing, soft link does not work, file not found error will be reported
 
Create a hard link a.hard a file, view metadata inodes, permissions, and size of a soft link to the file a.link.
[root@VM_0_15_centos ~]# ln a a.hard
[root@VM_0_15_centos ~]# ll -i
total 13456
394681 -rw-r--r-- 3 root root 6888896 Nov 10 21:42 a
394681 -rw-r--r-- 3 root root 6888896 Nov 10 21:42 a.hard
394522 lrwxrwxrwx 1 root root       1 Nov 10 21:45 a.link -> a
Summary: The properties of the original file and link files is exactly the same, exactly the same metadata.
 
When you delete a file, the case of hard-linked files a.hard
[root@VM_0_15_centos ~]# mv a a.bak
[root@VM_0_15_centos ~]# ll -i
total 13456
394699 -rw-r--r-- 2 root root 6888896 Nov 10 22:39 a.bak
394699 -rw-r--r-- 2 root root 6888896 Nov 10 22:39 a.hard
394522 lrwxrwxrwx 1 root root       1 Nov 10 21:45 a.link -> a
[root@VM_0_15_centos ~]# tail a.hard
999991
999992
999993
999994
999995
999996
999997
999998
999999
1000000
Summary: When the original file is missing, hard linked files can also be accessed.
[root@VM_0_15_centos ~]# echo "1">>a.bak
[root@VM_0_15_centos ~]# tail -1 a.hard
1
Summary: The relationship between the link and source files are similar: + synchronous replication update
 
Based on the above example, the difference between soft and hard links connected summarized as follows:
Difference between soft and hard links link: linux files in the file system, stored on disk partition no matter what type of things gave it assigned a number, called an inode number inode. As follows:
 1, flexible connection, in fact, to create a new file, which is designed to point to another file. With the original file inode inode soft connection is inconsistent
 2, a hard link is not established inode. He just inode link count in the domain where the original file to add 1 only, and therefore is not hard links across file systems.
 3, hard link is a file alias.
 4, soft links can span file systems, hard links can not be
 5, soft links can be linked to a file name that does not exist, the link does not work hard.
 6, soft links can be connected to the directory, not hard-wired
 7 Both links can be created by ln, ln created by default is a hard link
 8, using the -s switch can create a soft link.
 
 

Guess you like

Origin www.cnblogs.com/mwd-123/p/11832274.html