A symlink actually stores the path you give literally, as a string¹. That means your link ~/mylink
contains ".
" (one character). When you access the link, that path is interpreted relative to where the link is, rather than where you were when you made the link.
Instead, you can store the actual path you want in the link:
ln -s "$(pwd)" ~/mylink
using command substitution to put the output of pwd
(the working directory name) into your command line. ln
sees the full path and stores it into your symlink, which will then point to the right place.
¹ More or less.
"$PWD"
in POSIX shells and~0
inzsh
. – Stéphane Chazelas Aug 01 '14 at 09:41