DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
FREEDOM251

Freedom251 › Blog › deployment

How to Create and Manage Symbolic Links on a Linux Server

By Freedom251 Team · · 10 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use ln -s TARGET LINK_NAME to create a symbolic link (symlink): the target path comes first, and the new link name comes second. A symlink stores a pathname rather than a second copy of the target, so it can redirect a file or an entire directory tree, be switched during a deployment, or become dangling when its target is moved or deleted.

What a symbolic link is

A symbolic link is a filesystem directory entry containing a path to another file or directory. Programs that open the link normally follow that stored path and operate on the destination. The link itself has its own name and path, but it does not duplicate the target’s contents.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Because the link stores a pathname, a symlink can remain present even when that pathname no longer resolves. GNU Coreutils documentation describes this as a dangling symbolic link; there is no restriction against creating one. A dangling link is not a malformed directory entry. It is a link whose target is currently missing, renamed, inaccessible through the recorded path, or otherwise unresolved.

Symlinks are useful for configuration conventions such as sites-enabled, stable application paths such as /srv/app, and release switches such as /srv/www/current. Treat a directory symlink as a control-plane change: one short path can redirect every access to a large subtree.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Prerequisites and a safe working method

You need a Linux account with permission to create or remove a directory entry in the parent directory of the link. Creating a link does not require write permission to the target, although applications that later follow the link still need their normal permissions on the destination.

Before changing a production link, identify the exact parent directory, target, and intended link name. A reliable sequence is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Inspect the existing entry with ls -l and readlink.
  2. Decide whether the target should be absolute or relative.
  3. Create or replace only the intended link entry.
  4. Resolve the result with readlink -f or realpath.
  5. Run the service’s configuration check before reloading or restarting it.

Keep paths quoted in scripts when they can contain spaces or shell metacharacters. Use -- before a path supplied by an operator or another process when the command supports it, so a name beginning with a hyphen is not parsed as an option.

Create a symlink to a file

The basic syntax is:

ln -s TARGET LINK_NAME

The first operand is always the target path and the second is the new link pathname. For example, this enables one Nginx site configuration by linking the file into the enabled directory:

ln -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled/example.conf

Confirm the entry before asking the service to read it:

ls -l /etc/nginx/sites-enabled/example.conf

The listing should show the link name, an arrow, and the recorded target text. If a file already exists at the destination, ordinary ln refuses to replace it rather than silently destroying it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create a symlink to a directory

The same syntax works when the target is a directory:

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
ln -s /srv/releases/app-2026.10 /srv/app

Accesses through /srv/app now resolve into the release directory. The link is still only one directory entry; the files remain under /srv/releases/app-2026.10. Do not use a recursive removal command merely because the link points to a directory. Recursive operations can traverse into the target and affect real data if you operate on the resolved directory instead of the link entry.

Directory links are often used as stable names for changing releases. Verify the destination and ownership of both parent directories before switching one, because a typo can redirect a service to an unintended tree.

Absolute and relative symbolic links

An absolute target begins at the filesystem root, such as /srv/releases/app-2026.10. A relative target is interpreted from the directory that contains the symlink, not from the shell’s current working directory and not from the directory of a later user who follows it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Characteristic Absolute target Relative target
Example /srv/releases/app-2026.10 ../releases/app-2026.10
Resolution Starts at /. Starts in the symlink’s containing directory.
When the containing directory moves Still points to the same absolute pathname. Can continue to work when the link and target move together.
Mount or network portability Can fail or point to the wrong place when the same tree is mounted under another prefix or exposed on another machine. Avoids assuming a particular mount prefix when the relative layout is preserved.
Human readability The destination is immediately visible as a full path. You must reason from the link’s parent directory.

Creating a relative link manually

Suppose the link will live in /srv/www/current-parent and the release directory is a sibling under /srv/www. Change to the link’s parent and create the link with the relative pathname:

cd /srv/www/current-parent
ln -s ../releases/app-2026.10 current

The ../ component is evaluated from /srv/www/current-parent, so the stored text points to /srv/www/releases/app-2026.10 when followed through current. Running the command from another directory without accounting for the link’s eventual parent can create a link that resolves somewhere else.

Let GNU ln calculate the relative path

GNU Coreutils provides ln -s --relative TARGET LINK_NAME. It can calculate a relative target from canonicalized paths, reducing manual counting of .. components. Use it when both paths are known and you want the stored link to remain relative to the link location. Check the result with readlink; canonicalization can expose missing components or path assumptions before the link is used.

Creating an absolute link

ln -s /srv/releases/app-2026.10 /srv/www/current

This link continues to name /srv/releases/app-2026.10 even if /srv/www is moved elsewhere. That fixed behavior is valuable when the server’s directory layout is stable, but it is a liability if the same filesystem tree is mounted below a different prefix.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord | 6.35mm Jack, Durable Design, Stage and Home Studio Use, Low Noise Shielded Electric Cord for Bass, Keyboard, Amp, Mixer
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

Inspect the link itself and its destination

Use tools that distinguish the link entry from the path it names:

ls -l /srv/www/current
readlink /srv/www/current
readlink -f /srv/www/current
realpath /srv/www/current
  • ls -l displays the link name and the stored target text.
  • readlink prints the stored text without resolving it.
  • readlink -f resolves a canonical destination, following intermediate links and normalizing path components.
  • realpath also reports the canonical path when resolution succeeds.

A failed readlink -f or realpath call is a useful diagnostic signal: some component may be missing, inaccessible, or broken. It does not change the link.

Test a link in a shell script

Use test -L to identify a symlink itself, then test whether its target currently resolves:

if test -L "$link"; then
printf 'link text: %sn' "$(readlink -- "$link")"
if test -e "$link"; then
printf 'target resolvesn'
else
printf 'dangling linkn' >&2
fi
fi

test -L remains true for a dangling link because the directory entry is still a symlink. The second test separates an existing link from one whose target cannot be found.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Change a symlink without deleting its target

By default, ln refuses to replace an existing destination. GNU ln offers three different replacement behaviors:

Option Behavior Operational use
-f Unconditionally remove an existing destination and create the new link. Automation only after validating that the destination is the expected entry.
-i Prompt before replacing an existing destination. Interactive maintenance or a change window where an operator must approve the replacement.
-b Back up an existing destination before replacing it. When preserving a rollback copy is more useful than immediate deletion.

For a release switch, inspect first, replace deliberately, and verify afterward:

readlink -f /srv/www/current || true
ln -sfn /srv/releases/app-2026.11 /srv/www/current
readlink -f /srv/www/current

Here -s requests a symbolic link, -f permits replacement, and -n prevents a destination symlink to a directory from being treated as a directory during the operation. The exact combination should be tested on the local GNU/Linux system before production use.

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

When the destination might itself be a symlink to a directory and your intention is to replace that link entry, GNU’s -T (also written --no-target-directory) makes the no-directory interpretation explicit. This helps avoid following a destination link and creating a new entry inside an unintended directory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Safer replacement procedure

  1. Run ls -ld /srv/www/current and readlink /srv/www/current to establish what currently exists.
  2. Check that the new release directory exists and is the expected path.
  3. In a manual change, use ln -sni or another explicitly interactive form when your local ln supports the options together.
  4. In automation, verify that the current destination is either absent or the expected symlink before using force replacement.
  5. Resolve the new link and run the application’s or service’s validation command before reload.

Do not assume that a short replacement command is safe merely because the target is a directory. A mistaken destination pathname can alter the route to an entire application tree.

Remove a symlink safely

Remove the link name, not the destination:

rm -- /srv/www/current
# or
unlink -- /srv/www/current

These commands remove the directory entry for /srv/www/current. They do not remove the referenced file or directory. Confirm the object first:

ls -ld /srv/www/current
readlink /srv/www/current

Never add -r simply because the link points to a directory. If you intentionally need to delete the target tree, resolve and inspect that target as a separate operation, then use a command appropriate to the real directory. Keeping link removal and target deletion as two distinct decisions prevents accidental data loss.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Find broken symbolic links

To search a tree for symlinks whose targets do not resolve, use GNU find‘s -xtype l test:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
find /srv/www -xtype l -print

For every result, inspect the stored target and the surrounding directory:

readlink -- /srv/www/path/to/link
ls -ld /srv/www/path/to/link

Then choose one of three repairs:

  • Recreate or update the link if the target was intentionally renamed or moved.
  • Restore the missing target if the link is still the correct interface.
  • Remove the stale link with rm -- LINK_NAME or unlink -- LINK_NAME when nothing should use it.

Do not bulk-delete every result. A dangling link may be a planned placeholder, a mount that is temporarily absent, or a path owned by another deployment process. Confirm the search scope, ownership, and intended state first.

Choosing the right link style for deployments

Use an absolute link when the pathname is authoritative

An absolute link is straightforward to read in logs and remains pointed at the same pathname when the directory containing the link is moved. It suits a server whose filesystem layout is fixed and documented. The trade-off is that the link assumes the same root-level prefix everywhere it is used.

Use a relative link when the tree should move as a unit

A relative link can travel with its containing directory and target when their relationship stays the same. It is often better for relocatable application bundles, chroots, staged trees, and environments where a mount prefix differs between machines. Its cost is operational: administrators must calculate resolution from the link’s parent, not from the current shell directory.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Validate the switch as a control-plane change

For a release directory, inspect the existing link, confirm the new directory, replace only the link entry, resolve the result, and validate the service configuration. Keep the old release until the service has been checked so that a deliberate rollback remains possible. The symlink command changes name resolution; it does not copy files, migrate permissions, or prove that the new application is healthy.

Common failure modes and fixes

“File exists” from ln

The destination pathname already exists. Inspect it with ls -ld and readlink. If it is the intended symlink, choose an explicit replacement policy such as interactive, backup, or force. If it is a real file or directory, stop and determine why it is there before removing anything.

The link is dangling immediately after creation

Read the stored text with readlink and resolve it with readlink -f. For a relative link, evaluate the target from the directory containing the link. A common mistake is calculating the relative path from the directory where the ln command was typed rather than from the link’s eventual parent.

A service still reads the old release

Resolve the link and inspect the service’s configured pathname. The process may have opened files before the switch, may use a different path, or may require a configuration test and reload. Confirm the final link with readlink -f and use the service’s documented validation command before reloading.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A relative link works on one host but not another

Compare the parent directory and the relative layout on both hosts. Relative links require that relationship to remain intact. If the hosts intentionally use different layouts, create links appropriate to each layout or use an absolute path where a fixed pathname is the actual contract.

Removal appears to delete a directory

Stop and inspect with ls -ld. Removing a symlink with rm LINK_NAME or unlink LINK_NAME removes only the link entry. A recursive command aimed at a resolved directory is a different and potentially destructive operation.

Portability and GNU-specific options

The behavior and basic ln -s TARGET LINK_NAME syntax are standard across common Linux systems, but option details vary on non-GNU Unix implementations. GNU Coreutils 9.11 documents --relative, -f, -i, -b, and --no-target-directory; confirm availability and semantics with the local ln --help output and manual page before placing GNU-specific long options in a portable script.

Scripts should also account for command failure. Check exit statuses, quote variable-expanded paths, and print the resolved destination after a change. A successful creation command proves that a directory entry was made; it does not prove that the target exists or that an application can use it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Operational checklist

  • Put the target first and the link name second: ln -s TARGET LINK_NAME.
  • Choose absolute or relative storage based on relocation, mount layout, and readability requirements.
  • Remember that relative targets are resolved from the link’s containing directory.
  • Inspect stored text with readlink; resolve the canonical destination with readlink -f or realpath.
  • Expect ordinary ln to refuse an existing destination.
  • Select force, interactive, or backup replacement deliberately.
  • Use -T where replacing a destination link entry must not follow it as a directory.
  • Remove a link with rm -- LINK_NAME or unlink -- LINK_NAME, never with recursive removal by default.
  • Find unresolved links with find PATH -xtype l -print and review each result before repair.
  • After a deployment switch, resolve the link and validate the consuming service.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

deploymentLinuxLinux server administrationln commandsymbolic linksSymlinks

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.