650) this.width=650; "src=" Http://img.baidu.com/hi/youa/y_0034.gif "alt=" Y_0034.gif "/>
Command name: LN
Command English original meaning: link
Command path:/BIN/LN
Execute Permissions: All Users
Syntax: ln-s [Original file] [target file]
-S Create soft links
The file where the original file wants to generate the linked file
The file name of the destination file that establishes the linked file to the original file
#范例 $LN-S/etc/issue/tmp/issue.soft
[Email protected] ~]# ln-s/root/1.txt/testdir/1.test[[email protected] ~]# ll/testdir/total 4lrwxrwxrwx. 1 root root 19:26 1.test-/root/1.txt-rw-r--r--. 1 root root 12:18 a.txt
[[email protected] ~]# ln 1.text1 /testdir/1.test1ln: creating hard link '/testdir/1.test1 ' => ' 1.text1 ': invalid cross-device link# failed to create a hard link ... Error message "Invalid cross-device link" [[email protected] ~]# df filesystem 1k-blocks used available use% mounted on/dev/sda2 9948012 4403100 5032912 47% /tmpfs 502068 224 501844 1% /dev/shm/dev/sda1 40185208 81604 38055604 1% / boot/dev/sda3 9948012 23212 9412800 1% /testdir/dev/sr0 3824484 3824484 0 100% /media/centos6.8_final# view partition to learn that/testdir is a separate partition, Concluded that hard links cannot span partitions [[email protected] ~]# ln 1.text1 /tmp/1.text1[[email protected] ~]# ll /tmp/total 28-rw-r--r--. 2 root root 0 Jul 31 19:30 1.text1
#硬链接 [[email protected] testdir]# ll/tmp/1.text1-rw-r--r--. 2 root root 0 Jul 19:30/tmp/1.text1# soft link [[email protected] testdir]# ll/testdir/1.test lrwxrwxrwx. 1 root root 19:26/testdir/1.test-/root/1.txt
File type + permissions
A) File Type section (first letter)
"-" represents a file; "D" represents a directory; "L" denotes a soft link;
Hard link file type is file "-"
The soft link file type is the link file symbol "L"
b) Permissions Section
"R"--Indicates readable; "W"--Indicates writable; "X"--Indicates executable
Hard links for administrators can read and write to other people only readable permissions
Soft links are full permissions for everyone
#源文件/etc/passwd[[email protected] opt]# ll-h/etc/passwd-rw-r--r--. 2 root root 1.7K Jul 17:56/etc/passwd# link file [[email protected] opt]# ll-htotal 8.0Klrwxrwxrwx. 1 root root 19:59 Passwd.1-/etc/passwd-rw-r--r--. 2 root root 1.7K Jul 17:56 passwd.2# The soft link file size is only 11 bytes, it looks small, and the original file has 1.7k. In fact, even if the original file has thousands of bytes, its soft links are almost the same size. Because the soft link is just a symbolic link, used to link to the original file at the time of execution, soft links like Windows shortcuts, it is convenient for users to find some files or executable programs or file files, easy to plan and manage. Just a very simple link pointing, not representing the actual file or executable file itself. Comparing hard links and the original file, the other parts are identical except for the directory where the file name is located, including the size of the files. Just like a copy of the Preserve file property (cp-p), including file modification time is consistent.
#查看源文件内容 [[email protected] ~]# cat /etc/issuecentos release 6.8 (Final) kernel \r on an \mthe telnet is \lthe hostname is \h# View Soft Link content [[email protected] ~]# cat /opt/issue.1centos release 6.8 (Final) Kernel \r on an \mthe telnet is \lthe hostname is \h# view hard-link content [[ email protected] ~]# cat /opt/issue.2centos release 6.8 (Final) Kernel \r on an \mthe telnet is \lthe hostname is \h# adding content to source files [email protected] ~]# vim /etc/issue[[email protected] ~]# cat /etc/ issuecentos release 6.8 (Final) Kernel \r on an \mthe telnet is \lthe hostname is \h hello word! #查看软链接文件内容 [[email protected] ~] # cat /opt/issue.1centos release 6.8 (Final) kernel \r on an \mthe telnet is \lthe hostname is \h hello word! viewing hard-link content [[email protected] ~]# cat /opt /issue.2centos release 6.8 (Final) Kernel \r on an \mthe telnet is \lthe hostname is \h hello word! #从上面操作可以看到硬链接文件的内容随着原文件内容的更新而同步更新了, But the content of the soft link also seems to be updated, because the soft link itself is a link point, it points to the file content is the original file itself. Because of the synchronization update mechanism of the hard link, the original file content will be updated accordingly, so here see the content of the soft link also has the corresponding change.
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/85/3E/wKiom1ed8QHzSUqLAABs9oGk3JY461.png-wh_500x0-wm_3 -wmp_4-s_1702037447.png "title=" capture. PNG "alt=" Wkiom1ed8qhzsuqlaabs9ogk3jy461.png-wh_50 "/>
It can be concluded from the test that, after deleting the original file, the soft link will not find the file that the link points to. At the same time the soft link file information in the soft link directory and the link to the original file directory will be red, and the file directory will always blink, access can not find a soft link file. Hard-link files can still be accessed even if the hard-link original file is lost.
[Email protected] ~]# cd/opt/[[email protected] opt]# lltotal 4lrwxrwxrwx. 1 root root 20:49 issue1-/etc/issue# soft links will have arrows pointing to the location of the source file [email protected] opt]# ls-i/etc/issue./issue1./I Ssue2135260/etc/issue 427077./issue1 135260./issue2[[email protected] opt]# #而硬链接与软链接的显著区别在于硬链接与源文件的节点号一样且没有箭头指向源文件
Each Linux file has an I node, which is dispatched and managed by the kernel. However, in a Linux system, a file must have an I node, and an I node does not necessarily correspond to one file, hard link is a very special case, so when one of the files deleted, another file can still exist. hard links cannot span file systems, i.e. they cannot span partitions and devices.
650) this.width=650; "src=" Http://img.baidu.com/hi/youa/y_0033.gif "alt=" Y_0033.gif "/>
Command-ln-Notes