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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityIn 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.
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.
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?
cd $(mktemp -d)
does. Not everybody is familiar with this construction.
/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.
ln: 'foo': hard link not allowed for directory
.