technical question about hard links v soft links
Hi,
My understanding of a soft link is that it has its own filename, inode, and data--where the data is the filename of the original file. Then if you use the command: $ cat soft_link it traverses the chain: soft_link-->soft_link's inode-->data-->original's filename-->original's inode-->original's data and then the original's data is displayed. On mac os x, I created the original file and a hard link to the original file at different levels in the same directory (the same file system?), and then I created a soft link to the original file in a different directory(a different file system?): myHomeDir/testing/dir1/original myHomeDir/testing/hard_link /unixTesting/dir1/soft_link Then I did an ls -i on all those files, and they all displayed the same inode number. So, I formed a general rule in my mind: when you try to display the inode of a soft_link, you actually get the inode of the original file. That seems to be supported by the fact that if I rm(remove) the original and recreate it using touch original, the inode of the "new" original changes, and the inode displayed for the soft_link also changes(to the original's new inode number). My understanding of hard links is that they don't have their own inode--they are linked directly to the original's inode, and that is why the inode for the hard link is initially the same as the original's inode. But when the recreated original gets a new inode, it breaks the hard link. However, if I create original, soft_link, and hard_link in the same directory, then ls -i shows a different inode for the soft_link, and my general rule no longer holds. How should I interpret the fact that an ls -i on the soft link displays a different inode than the original's when the soft link is in the same directory as original? In addition, when I rm the original, and then recreate it using touch original, the original shows a new inode number, but the soft_link's inode remains the same, and the soft_link breaks. Why is that different from before? |
I get an different inode number of a soft link than of a file it links to. And that's how it should be. Symlink is a kind of object that points to an file, but exists in its location. It has a different inode.
Hard links, on the other hand, are two different names to the same thing. That's why I get the same inode number for hardlinks. When you remove the orginal file, you remove one pointer to it, in fact. The hardlink can be then considered as 'orginal'. So, when you re-create the file, you create a new file with different inode and so on. The hardlink does not point to it. |
Hi,
Thanks for the response. Quote:
Quote:
I'm familiar with all of the following: Quote:
|
All times are GMT -5. The time now is 03:20 PM. |