Create current.conf pointing to releases/v2/app.conf.
Store the target path in a symbolic link.
Which command is appropriate?
ln -s TARGET LINK_NAME creates a symbolic link containing the target path string.
Detailed explanation
ln releases/v2/app.conf current.confIncorrect. Without -s, ln creates a hard link.
ln -s releases/v2/app.conf current.confCorrect. ln -s releases/v2/app.conf current.conf creates the symbolic link.
cp -a releases/v2/app.conf current.confIncorrect. cp -a copies the file rather than storing a link target.
readlink releases/v2/app.conf current.confIncorrect. readlink reads an existing link and does not create one.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); mkdir -p "$tmp/releases/v2"; touch "$tmp/releases/v2/app.conf"; (cd "$tmp" && ln -s releases/v2/app.conf current.conf && readlink current.conf); rm -rf "$tmp"Expected result
releases/v2/app.confKey points
- -s means symbolic
- The link stores the target
- readlink can inspect it
Notes
- Environment: Linux / 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 symbolic link can cross filesystem boundaries and can become dangling when its target is absent.
Check the side effect
Read the link with readlink and test the link itself rather than following it.