Symlink paths

Written 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.

Stay in touch

Thanks for reading this article. I'd love to stay in touch and share more tips on programming and side projects with you. Sign up and I'll send you my articles straight to your email, you'll also get a free copy of the light themed version of my Git cheat sheet.
Git cheat sheet preview image