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.
Incorrect. Without -s this attempts a hard link.
ln -s releases/v2 currentIncorrect. It does not replace the existing link reliably without a force option.
Incorrect. 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.
Incorrect. -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.
Correct. 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 / 一時ディレクトリ
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.