原创 linux'short cut---link

2008-4-5 16:14 5175 14 14 分类: MCU/ 嵌入式

对应中文版:    http://blog.ednchina.com/likee/100229/message.aspx


 


As known to all of us that under the windows ,There is many “short cut” to use. On the contrary, Is there anything corresponding under the linux? If has, What is it ?  The answer is :of course have! That is “ link ”, “Link ” has many functions , it can separate to two parts: hard link and symbolic links.


一、Hard Links


From the last chapter , we know that, Before to read a certain file, the linux will first to read inode table. Only in this way , can the linux know where to load information. Of course , these informations are recorded in inode table . than the linux will follow the information in the inode and load the data from the block area to utilize.


Hard link is to establish a inode which called block .the inode is linked to this block. This means mapping. In this process,the real filesystem is not changed. So ,you can use either formar inode or the new inode to search .they can both point to where the filesystem is ,they are all the same. But it can cause problems. Because the inode can link to the block area , while the directory only use up the inode. In this way , hand link can not link directory. All in all , the Hard Link has some limitations:


1、  can not go beyond filesystem ..because all filesystems have their own inode table.


2、  Can not link directory.


二、symbolic Links


What is different with hard link is that: the symbolic will establish a independent filesystem .


So the filesystem will link the database to the file test. So if the format file is deleted , the symbolic links do not know where to link . so the symbolic links can not be opened .shown as: can not open the file…


Which link is much safer? In a way, hard link is much safer,because it has two inodes. If one of them is killed , if only one of them exists , the file will exists.but we know that hard link has many limits. So on the contrary, the symbolic links are more popular. For example:


Let us establish a fold named test under /root:


点击看大图


 


After establish the hard link , the information is as follows:


 


36e3f3c9-3a62-4632-bbad-d230faf2b3dd.jpg

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />


After establish the symbolic link ,the information is as follows:


 


88500c58-e107-4a04-a8c9-991a43659386.jpg


Delete the former file ,the information is as follows:


 


29e509bc-ca7a-42aa-b352-f12fef4f1c37.jpg


 


PS:


If there is no parameter, the defalt mode is hard link . described as above , after adding hard link, we discover that the attribution in link is added . what will happened when we kill the “passwd” now? If so ,the content of the passwd-hard will not changed .but the passwd-soft will not find the file.


If we use the attribute “-s”,this is much like the short cut in windows. But we must notice that,there is a defference between the two: In windows ,you can change the content of the short cut freely. This is very safe.bacause the formar file will not changed . but in linux, when you change the attribution of the link, the formar file will be changed follow the link.


For example :


ln –s  /bin/root/bin


if you enter the directory of /root/bin, if we change any of the file , the file of /bin will changed too! So we can say that , not all of the things under the /root is belonged to it. We still need to notice its sttribution!


 

 

 


 

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
14
关闭 站长推荐上一条 /3 下一条