Create a Symbolic Link in UNIX

Posted October 9, 2003 by Quinn McHenry in UNIX





cd /etc/rc2.d
ln -s ../init.d/httpd S77httpd

See also: Create a hard link in UNIX


About Quinn McHenry

View more articles by Quinn McHenry

The Conversation

Follow the reactions below and share your own thoughts.

  • Nathan Stiles

    cd /etc/rc2.d
    ln -s ../init.d/httpd S77httpd

    All rc links should be hardlinks. This is not a good example.

    • Tom

      Maybe you could provide the command syntax to make it a hard link:

      ln ../init.d/httpd S77httpd

  • Thomas

    > ln -s /export/space/common/archive /archive
    Just what i was looking for. Thanks!

  • Pranab

    What is the Difference between symlink and hard link

  • Vick

    A hard link is another name for an existing file; there is no difference between the link and the original file. So if you make a hard link from file `foo’ to file `bar’, and then remove file `bar’, file `foo’ is also removed. Each file has at least one hard link, which is the original file name itself. Directories always have at least two hard links–the directory name itself (which appears in its parent directory) and the special file `.’ inside the directory. Likewise, when you make a new subdirectory, the parent directory gains a new hard link for the special file `..’ inside the new subdirectory.

    • Jim

      Vick: Sorry, but that isn’t correct. If you have a file called ‘new’, for instance, and create a hard link called ‘new2′, both ‘new’ and ‘new2′ point to the same physical location on the hard drive. If you do an ‘ls -l new’ you will see something like:

      -rw-r–r– 2 new

      That *2* is the number of hard links to the file. Every file upon creation has one hard link to the location itself, which is why you normally see ‘1’ in this spot for files.

      Now, to get back to what I was explaining, if you have ‘new’ and ‘new2′ which is a hard link to ‘new’, and you delete ‘new’, the file is not gone. ‘new2′ still points to that file and is completely usable. Other hard links are not ‘magically’ deleted…and that is the value in a hard link.

      If ‘new2′ was a soft link, however, to ‘new’, and you deleted ‘new’, then ‘new2′ would still exist, but would not be valid any longer, since the file ‘new’ that it points to no longer exists.

      Hope this helps.

      • NN

        Thanks Jim for a very good explanation!

    • Jim

      Oh…sorry…one last thing…a file is not actually deleted unless its hard link count is 1. *THEN* it is gone.

  • nooby

    indeed I need some help! i’m absolutly new at linux! but I have to administrate a internalwebserver, which is running with Joomla 1.5. We had a symlink to a share on an other Server, but it doesn’t work now. I tried to link again with:

    sudo ln -s \\server\share /var/www/joomla15/slw/

    when I do this I get back, that the file does exist. But the hp the link doesn’t work! so awhat can I do?