Hard Link Question

Austin Godber godber at uberhip.com
Thu Feb 12 07:07:25 MST 2009


You cannot make hard links across partitions/devices.  You would have  
to make a symbolic link instead (ln -s src dest).


$ touch file1
$ ln file1 file1-hard
$ ln -s file1 file1-soft
$ stat file1*

   File: `file1'
   Size: 0         	Blocks: 0          IO Block: 4096   regular empty  
file
Device: 902h/2306d	Inode: 24084       Links: 2
Access: (0664/-rw-rw-r--)  Uid: (  503/  godber)   Gid: ( 1001/     dev)
Access: 2009-02-12 06:57:01.000000000 -0700
Modify: 2009-02-12 06:57:01.000000000 -0700
Change: 2009-02-12 06:57:10.000000000 -0700

   File: `file1-hard'
   Size: 0         	Blocks: 0          IO Block: 4096   regular empty  
file
Device: 902h/2306d	Inode: 24084       Links: 2
Access: (0664/-rw-rw-r--)  Uid: (  503/  godber)   Gid: ( 1001/     dev)
Access: 2009-02-12 06:57:01.000000000 -0700
Modify: 2009-02-12 06:57:01.000000000 -0700
Change: 2009-02-12 06:57:10.000000000 -0700

   File: `file1-soft' -> `file1'
   Size: 5         	Blocks: 0          IO Block: 4096   symbolic link
Device: 902h/2306d	Inode: 24091       Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (  503/  godber)   Gid: ( 1001/     dev)
Access: 2009-02-12 06:57:17.000000000 -0700
Modify: 2009-02-12 06:57:17.000000000 -0700
Change: 2009-02-12 06:57:17.000000000 -0700

Looking at the example above, you can see the differences between the  
two.  The symbolic link (file1-soft) is a reference to the original,  
while both the original file and the hard link have the same "Inode".   
This means the directory that is keeping track of these files is using  
that Inode reference to point to the data.  So the file and the hard  
link are the same thing as far as the filesystem is concerned.  Since  
the hardlink is just another directory entry with the same inode it  
can not span block devices since the Inode is a reference within the  
filesystem itself and wouldn't tell you WHICH device the Inode is on.   
Its also worth noting that "Links" is two for the file and hard link.   
This is the number of filesystem entries that are pointing to the data  
at that inode.  Delete one file and the link count goes down.

Austin


On Feb 12, 2009, at 6:42 AM, Tameek Henderson wrote:

> Morning,
>
> I have a noob question.  I have Ubuntu running on my Sony Vaio and  
> I'm happy to report all is well ...mostly.  I'm trying to create a  
> hard link in my home directory to my removable media card.  I tried  
> the following command (see below) but it says hard links are not  
> allowed even as root.  Any suggestions are greatly appreciated:
>
> Ln -t /media/disk ~
>
>
>
> Tameek Henderson
> 646.427.3205
> http://www.linkedin.com/pub/5/116/522
>
> Sent via BlackBerry from T-Mobile
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss at lists.plug.phoenix.az.us
> To subscribe, unsubscribe, or to change your mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>



More information about the PLUG-discuss mailing list