Is there a way for symlinks to have fallback? If the destination is not found, another one should be used.

I want to use a config file for a program that is different whether a drive is mounted or not. So I would have symlink to a config on that particular drive and if not found, it would use an alternative one.

I guess I could use a wrapper script that would check if a drive is mounted, link to a desired config and then run the application, but a wrapper script feels weird.

2 Answers 2


There isn't any way with standard symlinks. They always point to a single target path.

However, in your particular case, you could make use of how a drive shadows a mount: if you point the config file to /path/to/mount/config.cnf, then you have one that's on the parent filesystem (used when the mount isn't present) and one on the mounted filesystem (used when the mount is present).

But I wouldn't recommend that—for one thing, it's hard to open them both at once to e.g., compare them. I'd personally go for a wrapper script over that, many times over. There might also be program-specific ways, but you didn't name the program.

  • it's a qbittorrent. I usually download all my files on a external hdd, but if the disk is not mounted, all kinds of seeding errors pop out, files start redownloading and other mess. I weep every single time I accidentaly open qbittorrent without the drive mounted. So I'd have a alternative/fallback torrent/file location. Commented Sep 26, 2016 at 15:46
  • @JonnyRobbie yeah, I suspect you just need a wrapper script.
    – derobert
    Commented Sep 26, 2016 at 15:49

You can use a union mount for this. Showing one file if present in a certain place and another file if the first choice wasn't present is the whole point of union mounts. Symlinks won't help, except if to show the file in a different place from where the mount is.

mkdir ~/overridden
unionfs-fuse "/media/external:$HOME/overridable" ~/overridden

~/overridden shows a merge of the directory trees under ~/overridable and /media/external. When a file is present in both, the one from /media/external is shown.

See also Union mount on Linux (when someone answers it…).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .