--- title: ln โ€” Create Links date: 2026-10-18 time: 12:00 model: admin category: programs author_type: human summary: A command for creating hard links and symbolic links. Often used for deployment directory replacement and file sharing. tags: program, File and disk management, ln --- **๐Ÿ’ฌ "ln command"** ln creates an **alias (link)** to a file. Without `-s`, it creates a hard link; with it, a symbolic link. In practice, you create a **symbolic link that points to the current version** (for example, current โ†’ release-20261018) and use it for zero-downtime deployments. - **Concept**: A link points to the same content under another name without copying the file. - **Left column**: In `ls -l`, a symbolic link starts with `l` and shows `name -> target`. - **Hard link**: Shares the same inode. If you delete one name, the data remains as long as another name remains. - **Symbolic link**: A special file that contains a path. If the target disappears, it becomes a broken link. ## Common options | Option | Description | | --- | --- | | -s | Creates a symbolic (soft) link โ€” the default in practice | | -f | Overwrites an existing link if present | | -n | When the target is a directory link, replaces the link itself instead of the inside of the link | | -v | Prints what was created | ## 3 essential command combinations - `ln -sfn /opt/app/releases/20261018 /opt/app/current` โ€” atomically replaces the current version pointer - `ln -s /var/www/html/index.php /etc/nginx/html/index.php` โ€” symlinks the actual file into the configuration path - `ls -l /opt/app/current` โ€” shows where the link points **๐Ÿ’ฌ "Tell me the order to check when you receive a real customer inquiry."** Here are common situations you encounter on production servers, organized step by step. ### Step 1 ยท Prepare the new version directory Extract the new release into a separate directory. ``` tar -xzf /tmp/release.tgz -C /opt/app/releases/20261018 ``` ### Step 2 ยท Replace the pointer Use -sfn to change the current link to the new version. The replacement is atomic, so there is no momentary interruption. ``` ln -sfn /opt/app/releases/20261018 /opt/app/current ``` ### Step 3 ยท Verify Verify the link target and the service response. ``` ls -l /opt/app/current && curl -sI https://example.com | head -1 ``` ## How it is used in practice ### 1. Replacing the pointer for zero-downtime deployment **Situation** โ€” The web server points to /opt/app/current and you need to switch to a new version. ``` ln -sfn /opt/app/releases/20261018 /opt/app/current ``` **Result** โ€” The current link points to the new release, and new requests are served with the new code. **Point** โ€” Compared to copying the entire directory, this causes less disruption and rollback is done with a single link change. ### 2. Sharing configuration files **Situation** โ€” Multiple apps need to reference the same configuration file. ``` ln -s /etc/app/common.env /srv/app1/.env ``` **Result** โ€” Change it in one place, and it is reflected in all apps. **Point** โ€” Because unexpected synchronization issues can occur when apps write to the configuration, use this mainly for read-only sharing. ## Things to watch out for - Trying to overwrite an existing link without -f fails. The -sfn combination is the safest. - If you omit -n for a directory link, you can end up creating a link inside the link. - Relative-path symbolic links can break depending on the working directory, so absolute paths are recommended. - When deleting, confirm whether you are deleting only the link or also the original. ## Actual output The result of verifying that the current link points to the new release. ![ln command execution result: verifying the symbolic link target](https://games.aidebatehub.com/assets/ln-demo.png) Live production server --- Source (HTML): https://games.aidebatehub.com/programs/linux/filesystem/ln.html This file is an auto-generated Markdown twin of the DevHub document.