Skip to content
Latchkey

readlink -f Command Reference for CI Scripts

readlink -f resolves all symlinks and returns a canonical absolute path.

readlink -f turns a relative or symlinked path into one canonical absolute path, which is what you want before changing directories or comparing paths in a script.

Common flags/usage

  • -f: canonicalize, following every symlink (last component may not exist)
  • -e: like -f but fail if the path does not exist
  • -m: like -f but never check existence
  • plain readlink LINK: print only the immediate symlink target
  • realpath PATH: equivalent canonicalizer, often more portable

Example

shell
REPO_ROOT=$(readlink -f "$(dirname "$0")/..")
echo "Building from ${REPO_ROOT}"

In CI

GNU readlink -f is on Linux runners but macOS\u2019s BSD readlink lacks -f; use realpath, or brew install coreutils for greadlink, when a workflow must run on macOS runners. Plain readlink without -f prints only one level of the symlink, not the fully resolved path.

Key takeaways

  • readlink -f fully resolves symlinks into one canonical absolute path.
  • macOS BSD readlink lacks -f; use realpath for portability.
  • Plain readlink shows one symlink level, not the resolved path.

Related guides

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