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
basename and dirname Reference for CI Scriptsbasename and dirname split a path into filename and directory in CI. Reference for suffix stripping and the s…
ln -s Command Reference for CI Scriptsln -s creates symbolic links in CI for toolchains and shared paths. Reference for -s, -f, -n, and -r, plus th…
cp Command Reference for CI Scriptscp copies files and directories in CI for staging artifacts. Reference for -r, -p, -a, and trailing-slash beh…
find Command Reference for CI Scriptsfind walks directory trees and acts on matching files in CI. Reference for -name, -type, -exec, and -print0,…