I'm setting up the document root of my web server to point to a folder elsewhere on the disk. Should I be using a hard link, or a soft link, with the ln command?

Also, I'm having trouble getting the symbolic link pointing to a directory. I get the message ln: /Users/me/directory/: Is a directory when I try to set up the link.

  • Hard linked directories are most often not supported. Are you sure you are trying to ln -s the directory? – choroba Feb 9 '12 at 23:15
  • It's interesting that you refer to linux; I didn't know of any linux distribution with /Users/ as the folder for home directories; usually it's /home/. However, Mac OS X typically uses /Users/ to store the user's home directory. – Karolos Feb 9 '12 at 23:16
  • I'm on Mac OS X, but since I figured it would be best to ask the Linux community this question since the terminal has the same exact command. Tag added – bgcode Feb 9 '12 at 23:17

A soft link is enough for your purpose. You simply need to omit the trailing slash, i.e.

ln -s ~/me
  • Thanks. Why is a soft link better for this purpose? Trying to understand. – bgcode Feb 9 '12 at 23:16
  • 1
    The soft link points to the path of a file in the directory tree; the hard link points to the inode, i.e. the actually location of the data. As choroba mentioned, hard links are not often supported for directories. Also, hard links are linked to one file system, e.g. you couldn't make a hard link to a network file system. – Karolos Feb 9 '12 at 23:19
  • 1
    One advantage of hard links, though, is that, since you point to the data, the link is valid when you move the file being pointed to. In the case of a symlink (short for symbolic link), the link is just broken. – Karolos Feb 9 '12 at 23:21
  • 1
    @babonk: For more reading, you can start will all parts of cyberciti.biz/tips/… – Karolos Feb 9 '12 at 23:23
  • 2
    @babonk: To clear things up a tiny bit: "symbolic" and "soft" links are the same. Hard links are different. And by default, ln creates hard links. – grawity Feb 10 '12 at 0:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.