Soft and hard-wired connection

This article is from: http: //www.cnblogs.com/itech/archive/2009/04/10/1433052.html

Soft and hard-wired connection

1.Linux link the concept of
        Linux link the two, one is known as a hard link (Hard Link), the other is called a symbolic link (Symbolic Link). By default, ln command to generate a hard link.

] [Hardwired
hard connection means to connect via the inode. Files in the Linux file system, stored on disk partition no matter what type it gave assign a number, called an inode number (Inode Index).

In Linux, multiple file names point to the same inode is there. In general this is a hard-wired connection.

    The role of hard-wired to allow a file has multiple valid path name, so the user can create hard links to important documents, to prevent "accidental deletion" function. The reason described above, since there is more than one connection to be the directory inode. Only delete a connection does not affect the inode itself and other connections, only when the last connection is dropped, the connection data block and directory files will be released. In other words, the conditions are really delete files associated with hard-wired all files are removed .

] [Flexible connection (i.e., the symbolic link)
another call connection symbolic link (Symbolic Link), also known as soft connection. There are soft-linked files similar to Windows shortcuts . It is actually a special file. In the symbolic link, the file is actually a text file that contains the position information of another file

2. Experimental deepen understanding

[oracle @ Linux] $ touch f1 # create a test file f1
[@ the Oracle Linux] $ f1 F2 LN # f1 create a hard link file of F2
[@ the Oracle Linux] -s f1 F3 # $ LN create a symbolic link of f1 file f3, create hard and soft links differences in the parameters -s
[@ the Oracle Linux] $ # LS -Li -i parameter displays the inode information files
Total 0
9797648 -rw-r - r-- 2 the Oracle oinstall 0 Apr 21 F1 08:11
9797648-R & lt -rw - r-- 2 0 On Apr 21 is the oinstall Oracle 08:11 F2
9797649 lrwxrwxrwx Oracle. 1 2 On Apr 21 is the oinstall 08:11 F3 -> F1

As can be seen from the above results, the same hard-wired f1 f2 file, the original file is the inode, 9,797,648 are, however, different from the inode symbolic link file.

[oracle@Linux]$ echo "I am f1 file" >>f1
[oracle@Linux]$ cat f1
I am f1 file
[oracle@Linux]$ cat f2
I am f1 file
[oracle@Linux]$ cat f3
I am f1 file
[oracle@Linux]$ rm -f f1
[oracle@Linux]$ cat f2
I am f1 file
[oracle@Linux]$ cat f3
cat: f3: No such file or directory

Through the above tests can be seen: when the original file is deleted f1, f2 hardwired affected, but the symbolic link file is invalid f1

3. Summary

So you can do some of the relevant test, you can get all of the following conclusions:
1) delete symbolic links f3, for f1, no effect F2;.
2) delete hard-wired f2, to f1, f3 and has no effect;.
3). delete the original file f1, f2 is not hard-wired to the impact, led to symbolic links f3 failure;
4) deletes the original file f1, f2 hard-wired, the entire file will actually be deleted.

Guess you like

Origin blog.csdn.net/qq_33029793/article/details/89945847