Symlink use cases: Shortcuts, App config files

Image for post
Image for post

Shortcuts 🥱

Symbolic links are handy for shortcuts in your file explorer.

Maybe you have shortcuts on your desktop to your favorite folders, or maybe you symlink your active projects in your home directory for quick bash access.

For example:

ln -s /User/alex/Apps/2020/appthing /User/alex/appthing

This will create a shortcut to ~/Apps/2020/appthing directly in my home dir, i.e. cd ~/appthing

Notice how I used absolute paths when creating the symlink.

You don’t need to use absolute paths, but it’s the best way to stay out of trouble. But as you’ll see below, there are times when relative symlinks are useful.

App config files 🤔

This one is more interesting. We are going to use symlinks to expose a swappable, version controlled config collection to the application.

First I’ll explain the project (it’s very simple) and then I’ll talk about why I like it.

Here’s the folder structure of my project:

➜  appthing tree .
├── configs
│ └──
└── -> configs/

As you can see, there’s a configs folder containing some configuration This is linked to (a symlink file which, by the way, can be committed to version control):

cd appthing
ln -s configs/

Notice how I used relative paths when creating the symlink. This way the project can be cloned onto other computers or servers without the symbolic link breaking.

Here’s what my config file looks like:

➜  appthing cat
class config:
HELLO = "World"

and here’s what looks like:

➜  appthing cat
from config import config

Running it goes like this:

➜  appthing python

The point of using a symlink is to be able to quickly change the config file without needing to copy or move the current one.

Say that you needed another instance of this app running (with different config options) — you could make the new config file configs/ and quickly start testing them by swapping the symlink ln -s configs/

  • We can maintain a version controlled set of configuration files
  • App configurations can easily be exchanged (e.g. cloning multiple instances of an app to run on different configs)
  • Working version of config file is same as app config. No need to copy the file after saving edits (i.e. cp configs/ ⛔)


Thanks for reading. Let me know what you think in a comment below or on twitter.

Image for post
Image for post

Now get back to your projects, they are missing you ;)

Written by

Python Data Engineer, MSc. Physics

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store