Symlink paths

Written by Michael Lee on February 1, 2017

A lesson that I’ve learned tonight about symlinks are to always use the full path. I thought symlinks could be defined with relative paths if I’m already in the folder of the source files. Turns out that isn’t the case.

I have conf files for both nvim and tmux in a folder called dotfiles which is source controlled and hosted on GitHub. When creating symlinks while currently in the dotfiles, I thought the symlinks would resolve correctly with the source files in my dotfiles folder. But when re-sourcing nvim or tmux, I would get an error that the files didn’t exist.

Running ls -al from Terminal revealed that the symlinks weren’t correctly being linked to their source files.

# Current directoy ~/dotfiles
ln -s tmux ~/.tmux.conf

# Which yielded this symlink when running ls -al
.tmux.conf -> tmux

So instead this is how I should’ve symlinked my tmux conf file

ln -s ~/dotfiles/tmux ~/.tmux.conf

# Which now yields
.tmux.conf -> ~/dotfiles/tmux

Whether in the source folder or not, should always use the full path when creating symlinks.

Thanks for taking the time to read this article. I'd love to stay in touch and share more tips on programming and design, side projects and working remotely. Sign up and I'll send you my articles straight to your email.

:wave: Hey hey, I'm Michael Lee! I really appreciate you taking the time to read this article.

Be sure to check out my other articles.

Previous post: Feather icons