14 comment

  1. Hi,
    I wants to know that where are the links store?,is it created automatically at the time of creating the new file?Is it store in the inode or special file created for directory?
    what is different between the links and link count?


  2. this example was confusing
    because you are using
    the same name
    for the files
    for the paths

  3. Your /tmp example above assumes that a novice-user already knows the difference between ‘filesystems’ . This term is used interchangeably and the meaning depends on the context where[how] it’s used.

    /tmp above implies it’s on a different partition (and may be possibly another filesystem(ext2 rather than ext3(/home)).

    Subtle meaning
    1) A FSH – example all dir’s under ‘/’ on a single partition.
    2) Different (logically grouped or part of entire hierarchy)dir’s under same partition ,different partition’s or on different type-of-filesystem(ext2[3],reiser etc).

    Anyways, keep up the good work.

  4. hi,

    I need some clarification.

    I am very clear that hard links points to same inode number.
    Now if you try to create a hard link for /tmp file system it will lead to confusing references for UNIX or Linux file system. Is that a link no. 782263 in the /home or /tmp file system? To avoid this problem UNIX or Linux does not allow creating hard links across file system boundaries
    If i am trying to create hard link for /tmp file system.
    For example:
    $ cd /home/karan
    $ touch sfile
    $ ln sfile hfile
    $ ls – ali
    4489496 -rw-r–r– 3 karan karan 0 2008-12-19 13:41 hfile
    4489496 -rw-r–r– 3 karan karan 0 2008-12-19 13:41 sfile

    very clear till this part.

    Do you meant to say that we cannot create hard links like the below?

    $ ln sfile /tmp/hfile

    If i misunderstood,please do clear me.


  5. Karan,

    If the /tmp directory is on the same partition as where ‘sfile’ is, then you can hard link it. You can’t hard link across different partitions/disks. They’re different file systems, therefore the inodes differ on each partition.

  6. Otherwise to say, the inode number will not and can not be unique across filesystems / servers / partitions.

    Hope this helps.

  7. I was just wondering how I could make a link to a drive?
    When I do
    root@Ubuntu9:media > ln -s disk disk
    it returns an error saying /media/disk already exists!

    I know it exists I just want to make a link to it (shortcut),
    I know it seems dumb/redundant to make a same name link in the same folder but I was trying to figure out why this disk does not mount?and thought it may help because the cdrom and other disks mount OK and they all have links in the /media!
    when I do mount disk it returns the usual fstab nonsense. It (disk) ONLY come up when I use the GUI and go in My Computer, then it appears in the /media directory?
    So I thought it has something to do with making a link?

  8. In general we create softlink for sortcut, If you already have file or folder name on current directory, why do you want same name softlink, it does not make sense to have duplicate softlink or even hardlink on same folder or in otherwords, directory maintains filenames and it requires uniq names you can not have duplicate names for given file in same folder.

    if you are planing to create softlink from different partition or folder, it should not cause any problem.

    Look at following example, I am creating data.txt to data.txt it gives error but when I tried data.txt to data1.txt, it works fine.
    ln -s data.txt data.txt
    ln: creating symbolic link `data.txt’: File exists
    ln -s data.txt data1.txt
    ls -la data*.txt
    lrwxrwxrwx 1 root root 8 2009-08-13 00:02 data1.txt -> data.txt
    -rw-r–r– 1 root root 15 2009-08-12 23:53 data.txt

    Hope this helps,
    Babu Satasiya

  9. Thanks Babu,
    I used different name and it worked.
    I was testing to see why this 60 Gig hard drive does not mount on ts own while th cdrom0 and floppy0 loaded no problem!?

  10. It’s probably worth mentioning that symbolic links can cross file systems and hard links cannot.

    That’s only because systems programmers are too dumb to come up with hard links that do cross filesystems. Or bidirectional hard links. Or directional hard links.

    [Hard links that cross filesystems would look more and more like symbolic links. Perhaps a more elegant implementation than a pathname-stashed-in-a-file-with-a-particular-bit-in-the-inode-set, but the semantics of a Unix hard link, which make lots of assumptions about the physical layout of the device, clearly don’t apply. When you add in the fact that a cross-volume link might point to a device which isn’t mounted or otherwise isn’t available (a remote filesystem across a network which is down), failure semantics must be thrown in as well.]

    [A counter-example–even one of research quality only–might be a good thing, though.]

    How would a hard link cross file system boundaries without becoming a symbolic link?

    Easy, it’s a chain of hard links. The first link in the chain points to the remote object component and has the name of the link to follow in it. The link in the remote system is either a hard link pointing to the target or it’s another link that points to a remote object component and has … blah blah. And of course, this is bidirectional.

    The trick is that since these links are all in the root>>portals of the systems in question, they’re inaccessible to the casual user even if they “cross” user-space. As a consequence, they can’t be broken by a casual user but must be deleted properly by someone with legitimate permission to do so, or broken by the owner of one of the systems in the chain. IOW, these are NOT symbolic links!


  11. I want know about u have create a hardlink that time delete man hardlink file. then u have access that file or not tell me please

  12. with what Franklin put forth, go over the example again. When spanning multiple FS you may encounter duplicate inodes. On a single physical HD with multiple mount points most FS (that i know of) keep track of the data by drive. the inodes are created in a incremental fashion.

    -Eric Peyser

  13. I may date myself here —-but –Unix beyond the magic garden– was a great book. It had alot of internals. from FS and the internals to IPC and named/unnamed pipe info. It helped me to understand what was behind the screen. BTW article was great !!!!

    Have a question? Post it on our forum!