Thread: Directory link

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    80
    Rep Power
    12

    Directory link


    Hello,

    I'm trying to create a link to a directory. I have looked @ the man pages but no joy.

    pwd
    /usr/local/www/data/

    ln -fh testarea /home/user/testarea
    link: testarea: Is a directory


    with
    in -fhs testarea /home/user/testarea

    that seems to work but when I access the link I run into this error

    /home/user/testarea: Too many levels of symbolic links.

    Thanks in advance!
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    9
    Rep Power
    0
    Wait, you're creating the link _to_ the directory? You've got your arguments backwards. ("ln creates a link to an existing file source_file. If target_file is given, the link has that name ....")

    The man page is confusing as hell. "target_file" and "target_directory" should be replaced throughout with "link_name" or some such.

    Regarding the first error you were getting, directories cannot be hard linked, only symbolically linked.

    K.C.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    80
    Rep Power
    12
    Thank you for your reply.

    So how would I go about creating a link to a directory?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    9
    Rep Power
    0
    One would create a link to a directory like this :

    ln -s /path/to/realdir [name_of_link]

    The name of the link is optional; without it the link name will be the same as the "source" file or directory. In this case, "realdir".

    So, in your case, the following should be sufficient (if I am guessing your intentions correctly) :

    cd /usr/local/www/data/
    ln -s /home/user/testarea

    ... which would leave you with a link in /usr/local/www/data/ that looks like a subdirectory named testarea and points to the actual subdirectory /home/user/testarea .

    K.C.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    80
    Rep Power
    12
    That did it..... thanks!
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    South Yorkshire
    Posts
    442
    Rep Power
    23
    Only 2 and half years late

    But still a solution.

    I wanted the directory linking from a location to a users ftp home folder, but using symlink the links were not available in ftp, whether this was the ftp server hidding them or not I'm not sure.

    But found a nice method using the mount command, this allowed me to create a link between the destination and was also available in FTP clients.

    mount --bind <DESTINATION> <NEW FOLDER>

    This is only available till next restart, to have the mounted directory available after restart, add the following line to your /etc/fstab file

    <DESTINATION> <NEW FOLDER> none bind
    Last edited by pgudge; September 27th, 2005 at 10:44 AM. Reason: added fstab info
    regards,

    pgudge

IMN logo majestic logo threadwatch logo seochat tools logo