Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
I have heard that creating hard link to a directory is not possible however when reading the man page of "ln" the "-d/-f" option says hard link directories ( super-user ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493

    creating hard link to directory


    I have heard that creating hard link to a directory is not possible however when reading the man page of "ln" the "-d/-f" option says hard link directories ( super-user only). Thus this mean the super user i.e root can create hard link to directory and not a normal user , If yes then you . Even on specifying the above options I get a operation not permitted for a super user.
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,695
    You can only hard link files (and I would assume this also goes for directories) if the source and target are on the same file system. You cannot hard link a file on one device to a directory on another device or partition (different file system).
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    478
    from "man ln"

    "-d, -F, --directory
    allow the superuser to attempt to hard link directories (note: will
    probably fail due to system restrictions, even for the superuser)"
    the sun is new every day (heraclitus)

  4. $spacer_open
    $spacer_close
  5. #4
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493
    hey thanks for replying
    Rubberman have you tried making directory hard link ???
    Quote Originally Posted by tpl View Post
    from "man ln"

    "-d, -F, --directory
    allow the superuser to attempt to hard link directories (note: will
    probably fail due to system restrictions, even for the superuser)"
    Which distro are u using . I m using RHEL 4
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

  6. #5
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,049
    Quote Originally Posted by vickey_20
    Rubberman have you tried making directory hard link ???
    I may not be Rubberman, but I've tried it.


    It cannot be done

    But soft links work perfectly well.
    Can't tell an OS by it's GUI

  7. #6
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493
    but if it can't be done then why is there an intimation for the same in the man pages.
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

  8. #7
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,049
    Quote Originally Posted by vickey_20
    but if it can't be done then why is there an intimation for the same in the man pages.
    Indicating that it will probably fail, even for root.


    Quote Originally Posted by wikipedia
    Most modern operating systems don't allow hard links on directories to prevent endless recursion. A notable exception to this is Mac OS X v10.5 (Leopard). Symbolic links and NTFS junction points are generally used instead for this purpose.(source)
    Can't tell an OS by it's GUI

  9. #8
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493
    ok got your point but it is not supposed to be there then why the heck is it metioned in the man pages in the first place. Are there any distribution of linux which support it , otherwise the presence of -d/f option doesn't make sense .
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

  10. #9
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Well, I am not a master on fs's but...

    First thing to note is that linux != ln, even more, ln is not part of linux.

    The GNU tools might run in a different number of operating systems with a variety of kernels. This depends on many things, but mainly the game is between the kernel and the file system driver (for whatever fs you are using). So, that "ln" of "df" can do it, doesn't mean that "linux" necessarily support that feature. And even if that was possible in linux, it doesn't mean that your file system will support it at all (just like vfat doesn't support linux/unix permissions).

    There are some interesting readings about this around:

    The Answer Gang 93: hard links
    hard links to directories [LWN.net]


    The main problem with hardlinking directories is that when you make a hard link, there's no difference between the names of a given file or directory. And the file remains accessible until you delete the last one (unlike with symbolic links). This can confuse the programs that walk recursively the directory tree, who knows where our rm -rf could end. Unlike with symlinks, you don't have to deference anything, virtually, the directory is just there like if you created it with mkdir, and whatever hangs inside it will be recursed as well.

    Symbolic links on the contrary are easily identifiable and avoidable to deference when needed.

    You see that on the man page because simply no one has ever forbidden that, and posix don't say anything against that either. But I know of no OS/fs that actually implemented the feature (that doesn't mean it doesn't exist, maybe it does). It just means that the linux kernel and native fs's do not support it.

    Any distro supporting this, if there's any at all, will have a patched kernel for sure. AND -more importantly- don't expect that a standard linux fs created with such a distro (if it exists at all) will be mountable/readable/portable to other -standard- linux OSes. At least not without a previoius fsck.

  11. #10
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,695
    Well, I tried it on my CentOS 5.3 and it fails with the error message "Operation not permitted". There may be linux versions that allow it, and it might be a factor of the file system in question. Don't know. Not sure I care.

    So, why do you want a hard link to a directory?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •