5

When linking a directory to root, I get this error:

$ ln -s ~/inbox/ /
$ ln: //: Is a directory

Bash autocompletes the directory path by adding a /. I've tried escaping without success.

$ ln -s ~/inbox /

works though. Why is this?

  • 2
    What you wrote cannot work, I think you have to add more detail to your question. Also, are you working as root? Also, what exact OS are you on? – jippie May 9 '12 at 18:25
  • What OS is this? Is it GNU Coreutils, or the BSD utils? – jsbillings May 9 '12 at 19:46
  • I don't think it's coreutils. My version puts the file name in quotes, e.g. ln: 'foo': hard link not allowed for directory. – Mikel May 9 '12 at 20:43
4

In pathname resolution, having a trailing / is equivalent to a trailing /. — in other words, ~/inbox/ is equivalent to ~/inbox/. in this context. So the ln command is trying to create a link called . in the root directory (and, unsurprisingly, failing).

Zsh removes the trailing / when you press Space after completing a directory (unless configured not to do so). I don't know if bash can be made to do this.

  • Very interesting. Pathname resolution also says that symlinks should be resolved. But when you do ln symlink blah, blah should point to symlink, not what symlink points at. – Mikel May 10 '12 at 4:16
0

Is that exactly what you ran?

Is a directory looks like your OS printing the EISDIR error, which could happen two ways:

Trying to overwrite an existing symlink that points to a directory.

$ cd $(mktemp -d)
$ mkdir dir
$ ln -s dir dir    # this creates dir/dir
$ ln -s dir dir    # this fails, because dir/dir already exists
ln: failed to create symbolic link `dir/dir': File exists

Trying to create a hard link to a directory.

$ cd $(mktemp -d)
$ mkdir dir
$ ln dir dirlink
ln: `dir': hard link not allowed for directory

If it is what you were running, what does type ln or alias ln print?

  • I think it is good to explain what cd $(mktemp -d) does. Not everybody is familiar with this construction. – jippie May 9 '12 at 21:07
  • 1
    It creates a new directory somewhere under /tmp. It makes sure that the files I'm using in my examples don't already exist so that everyone can get try running the commands and get the same results. – Mikel May 9 '12 at 21:18

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.