ln: Usage, Options & Common CI Errors
ln creates links - symbolic (-s) pointers or hard links to the same inode.
ln wires up symlinks for toolchain shims and "current" release pointers. The two recurring CI errors are "File exists" (no -f) and links that dangle because the target path was relative.
What it does
ln creates a new link to a file. Without -s it makes a hard link (another name for the same inode); with -s it makes a symbolic link (a path pointer that can cross filesystems and point at directories).
Common usage
ln -s /opt/app/releases/v2 /opt/app/current
ln -sf node-18 node # force-replace existing link
ln -s ../shared ./shared # relative target
ln -snf /new/target link # safely retarget a dir symlink
ln file.txt hardlink.txt # hard linkOptions
| Flag | What it does |
|---|---|
| -s / --symbolic | Make a symbolic link (not hard) |
| -f / --force | Remove an existing destination first |
| -n / --no-dereference | Treat an existing-link dest as a file |
| -r / --relative | Make a symlink target relative (GNU) |
| -T | Always treat dest as a normal file |
Common errors in CI
ln: failed to create symbolic link "X": File exists - the destination already exists; add -f (and -n when it is a symlink to a directory, else you create a link inside the target). A symlink with a relative target resolves relative to the link's location, so it dangles if you move the link - use an absolute target or ln -r. Hard links cannot cross filesystems or link directories.