Skip to content
Latchkey

ln -s Command Reference for CI Scripts

ln -s creates a symbolic link that points at another path.

Symlinks let CI pin a stable name to a versioned install (a "current" toolchain) or expose a binary on PATH. The relative-vs-absolute target choice trips people up.

Common flags/usage

  • -s: make a symbolic (not hard) link
  • -f: remove an existing destination first
  • -n: treat an existing symlink destination as a normal file, not a dir
  • -r: make the link target relative (GNU)
  • ln -s TARGET LINKNAME: TARGET first, then the new link name

Example

shell
ln -sfn "/opt/node/${NODE_VERSION}" /opt/node/current
ln -sf "${PWD}/bin/tool" /usr/local/bin/tool

In CI

Use ln -sfn together when repointing a "current" symlink: -f replaces it and -n stops ln from descending into the old link and creating a nested link instead. A relative target (or -r) keeps the link valid if the tree is moved or mounted at a different prefix; an absolute target breaks then.

Key takeaways

  • ln -s TARGET LINK takes the target first, then the new link name.
  • ln -sfn safely repoints an existing "current" symlink in place.
  • Relative targets survive a moved or remounted tree; absolute ones may not.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →