current is an existing symbolic link to releases/v1.
Replace it with a symbolic link to releases/v2 using GNU ln.
Which command is appropriate?
GNU ln -sfn creates the symbolic link, forcibly replaces the existing link name, and treats a destination symlink as a link rather than following it.
Detailed explanation
ln releases/v2 currentIncorrect. Without -s this attempts a hard link.
ln -s releases/v2 currentIncorrect. It does not replace the existing link reliably without a force option.
ln -f releases/v2 currentIncorrect. -f alone does not request a symbolic link.
ln -sfn releases/v2 currentCorrect. ln -sfn releases/v2 current atomically updates the link name in the intended way.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); mkdir -p "$tmp/releases/v1" "$tmp/releases/v2"; (cd "$tmp" && ln -s releases/v1 current && ln -sfn releases/v2 current && readlink current); rm -rf "$tmp"Expected result
releases/v2Key points
- -s is symbolic
- -f replaces an existing destination
- -n avoids following a destination link
Notes
- Environment: GNU coreutils 9.x / 一時ディレクトリ
- Use disposable files and directories for link experiments.
- Link behavior can differ for special filesystem objects and cross-filesystem operations.
Foundation review
Place the operation
A stable `current` link can switch releases while callers keep using the same pathname.
Check the side effect
Perform the switch only in a temporary directory and verify the resulting target with readlink.