9

I have an issue with ln -s on Ubuntu 14.04, while using it in the following scenario:

$ cd ~/programming/tmux/
$ ln -s tmux ~/bin/tmux
$ ls -l ~/bin/tmux
lrwxrwxrwx 1 USER USER 4 sie 31 11:02 /home/USER/bin/tmux -> tmux

Why is it like so? When I create it giving the absolute path everything works fine:

$ ln -s ~/programming/tmux/tmux ~/bin/tmux
$ ls -l ~/bin/tmux
lrwxrwxrwx 1 USER USER 4 sie 31 11:02 /home/USER/bin/tmux -> ~/programming/tmux/tmux
Patryk
  • 14,096
  • The shell expands ~ so ln never sees ~. And if it did, it wouldn't be able to make sense of it and it would fail with a file not found error. You can see this if you quote your link, ala '~/bin/tmux' – bsd Aug 31 '14 at 09:49

1 Answers1

13

When you write

ln -s VALUE link_name

it creates a symbolic link with value VALUE. This is what you got. If you want to create a relative link, it is best to cd to the directory where you want to put the link:

$ cd ~/bin
$ ln -s ../programming/tmux/tmux .

Shell completion will help you.

vinc17
  • 12,174
  • 2
    You can also use -r flag. It will calculate link's value relative to its final destination, not your current working directory. – AkaZecik Jul 12 '20 at 07:02
  • @AkaZecik Yes, but the -r flag is a GNU extension, thus not available everywhere. – vinc17 Jul 12 '20 at 11:17