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.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Use ln -s TARGET LINK_NAME to create a symbolic link on a Linux server. The target comes first; the new link name comes second. A symlink stores a pathname rather than file data, so it can redirect a file or an entire directory tree, become dangling when its target disappears, and be removed without deleting the target.

This guide shows how to create, inspect, switch, test, repair, and remove symlinks safely, including the choice between relative and absolute targets and the GNU-specific options commonly used in deployment scripts.

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

What a symbolic link is

A symbolic link, or symlink, is a filesystem directory entry containing a pathname to another file or directory. Programs normally follow that pathname when they access the link. The link itself does not contain a second copy of the target’s contents.

For example, a web server can read /srv/www/current while that name points to /srv/releases/app-2026.10. Changing the link can switch the active release without moving the release directory or changing every configuration file that refers to /srv/www/current.

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application:Upgraded attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Warranty & Support: Our Electric air duster comes with 5 years warranty and 24/7 customer service. During this period, if you have any questions,pls kindly feel free to contact us.
  • A symlink can point to a regular file, directory, socket, or another pathname.
  • The target may be relative or absolute.
  • The target does not have to exist when the link is created. GNU Coreutils documents that dangling symbolic links are allowed.
  • Deleting the link name is different from deleting the object it references.

Because a directory symlink can redirect every pathname below it, treat changes to links such as /srv/app, /var/www/current, or a service’s configuration path as control-plane changes. Check the destination before restarting a service or exposing the path to users.

Create a symbolic link

Link a file

Use this form:

ln -s TARGET LINK_NAME

To expose an Nginx site configuration through an enabled-directory name:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ln -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled/example.conf

The first operand is the stored target pathname. The second operand is the directory entry that users and applications will open. Confirm the result before reloading Nginx:

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

Typical output begins with l, identifying a symbolic link, and shows an arrow to the target. The command creates a new link only; it does not copy the configuration file or alter the target’s permissions.

Link a directory

The syntax is the same for a directory:

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

After this command, a request for /srv/app/logs is resolved through the release directory. The link does not merge the two directories: entries physically inside /srv/app are not stored there, and creating or deleting files through the link changes the target directory.

Before redirecting a production path, check the target’s owner, permissions, expected release contents, and the process that will follow the link. A typo in a directory link can expose the wrong subtree or cause a service to start with missing files.

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

Create a link when the target does not yet exist

Linux permits a dangling link:

ln -s /srv/releases/app-2026.12 /srv/www/next

This succeeds even if /srv/releases/app-2026.12 is absent. The link becomes usable when that exact pathname later resolves. A dangling link is therefore not necessarily a failed command; it may be an intentional placeholder, but production checks should distinguish it from a ready destination.

Choose a relative or absolute target

Absolute symlinks

An absolute target begins at the filesystem root, such as /srv/releases/app-2026.10:

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
ln -s /srv/releases/app-2026.10 /srv/www/current

GNU Coreutils states that an absolute symlink always points to the same pathname even if the directory containing the link is moved. This makes the destination immediately readable and avoids calculating a path from the link’s parent directory.

The fixed pathname is also a limitation. If the same directory tree is mounted under another prefix, unpacked into a staging root, or exposed through a network filesystem with a different layout, the absolute link may point outside that tree or fail entirely.

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

Relative symlinks

A relative target is interpreted from the directory that contains the link, not from the shell’s current working directory when another person later follows it. For example:

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

If the link is stored as /srv/www/current-parent/current, the target ../releases/app-2026.10 is resolved relative to /srv/www/current-parent. It therefore names /srv/www/releases/app-2026.10 in this example. Moving the whole parent tree while preserving that relationship can keep the link working.

Relative links are useful for portable application bundles, chroots, extracted artifacts, and trees that may be mounted under different prefixes. They require more care during creation because the same text can resolve to a different location when stored in a different directory.

Let GNU ln calculate a relative path

GNU ln supports --relative (also written -r) to calculate a relative target from canonicalized paths:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ln -s --relative /srv/releases/app-2026.10 /srv/www/current

Use this when you know the intended source and link locations but do not want to calculate the required sequence of ../ components manually. Confirm the resulting stored text with readlink; canonicalization can expose unexpected mount points, missing components, or path spelling differences.

Decision table

Concern Relative target Absolute target
Moving the containing tree Can continue to work when the link and target move together with the same relative layout. Continues to use the original root-based pathname, even if the link’s parent moves.
Different mount or deployment prefix Usually avoids dependence on the prefix outside the tree. Can fail or resolve to the wrong tree when the prefix changes.
Human readability Requires reasoning from the link’s parent directory. Destination is explicit at a glance.
Creation risk Easy to calculate from the wrong directory; use the link location or --relative. Less ambiguity during creation, but can encode an environment-specific path.
Common use Self-contained releases, portable bundles, and relocatable trees. Stable system paths and configurations whose root location is intentional.

Inspect a link without following it accidentally

See the link and its stored text

Use ls -l for a human-readable listing:

ls -l /srv/www/current

Use readlink when you need the exact pathname stored in the link:

Rank #3
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.
readlink /srv/www/current

readlink prints the link text. For a relative link, it prints the relative text; it does not automatically turn that text into an absolute destination.

Resolve the canonical destination

Use readlink -f or realpath when you need the resolved destination:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
readlink -f /srv/www/current
realpath /srv/www/current

These commands resolve path components and produce a canonical pathname. If canonicalization fails, a component may be missing, inaccessible, or part of a broken chain of links. That failure is useful evidence, but it does not tell you by itself whether the stored link text or a later component is at fault; inspect each component.

Distinguish a symlink from its target in scripts

The shell test -L checks whether a pathname is a symbolic link, including a dangling one. The test -e checks whether the pathname resolves to an existing object:

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

Use -- before a user-controlled pathname so a name beginning with a hyphen is not interpreted as an option. Quote the variable so spaces, wildcard characters, and newlines in a pathname are not split or expanded by the shell.

Check a directory link before a service action

  1. Run ls -ld LINK_NAME to inspect the link entry itself rather than listing the target directory’s contents.
  2. Run readlink -- LINK_NAME to record the stored target text.
  3. Run readlink -f -- LINK_NAME or realpath -- LINK_NAME to verify the canonical destination.
  4. Check ownership and permissions on every parent directory and on the resolved target.
  5. Only then reload or restart the service that consumes the path.

Change a symlink during a deployment

Why a plain second ln -s fails

By default, ln refuses to replace an existing destination. This protects an existing file or link from being silently overwritten. A release switch must therefore choose an explicit replacement policy.

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.

Inspect, replace, and verify

A controlled release switch can look like this:

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

The first command records the current resolved release; || true allows the sequence to continue if the current link is dangling. The replacement command uses GNU options commonly used for this pattern: -s creates a symlink, -f removes an existing destination before creating the new link, and -n prevents a symlink-to-directory destination from being treated as a directory to enter. The final command verifies the new destination.

Do not treat -f as a substitute for validation. In automation, first check that the existing destination is the expected symlink and that the new target is an approved release directory. A typo, an unexpected directory, or an attacker-controlled path can turn an unconditional replacement into a destructive change.

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.

Use interactive or backup behavior when appropriate

  • ln -sfi TARGET LINK_NAME adds -i, prompting an operator before replacement. This is suitable for a supervised change window, not unattended automation.
  • ln -sfb TARGET LINK_NAME adds -b, asking GNU ln to make a backup of a replaced destination according to its backup policy. Confirm where that backup is written and how it will be cleaned up.
  • --no-target-directory (or -T) tells GNU ln to treat the destination operand as the link entry itself. This is useful when the destination might itself be a symlink to a directory and the intention is to replace that link, not create a new entry inside the directory it names.

Interactive prompts and backups solve different operational problems. A prompt adds human approval; a backup preserves a previous name for recovery. Neither verifies that the new target is safe, so perform destination validation separately.

Make the switch observable

Record the old and new resolved paths, the command’s exit status, and the deployment identifier in your change log. After switching, test the application through the stable link path and inspect service logs. If the service has a configuration-test command, run it before reloading; a valid symlink does not guarantee valid application contents.

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

Remove a symlink safely

Remove only the link entry with either command:

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

These commands do not remove the referenced file or directory. The target remains at its own pathname and can still be reached directly or through other links.

Verify the object before removal:

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

Do not add a recursive option merely because the link points to a directory. A recursive operation aimed at a path that has been resolved incorrectly, or at the target itself, can delete real data. If the name is a directory rather than a symlink, stop and investigate instead of forcing the command.

After removal, test -L /srv/www/current should fail. Removing a symlink may leave an application without its expected path, so coordinate the change with the service using it.

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

Find and repair broken symlinks

To list dangling symbolic links under a tree, use GNU find:

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

-xtype l selects links whose referenced object cannot be resolved. For each result:

  1. Print the stored target with readlink -- PATH.
  2. Resolve it with readlink -f -- PATH and note which component is missing.
  3. Check whether the target was renamed, the parent filesystem is unmounted, or permissions prevent traversal.
  4. Decide whether to recreate the link, restore or rename the target, or remove the stale link.
  5. Limit any cleanup command to the reviewed path set; do not bulk-delete before understanding ownership and scope.

A link can be syntactically valid while dangling. For example, renaming /srv/releases/app-2026.10 to app-2026.10-retired leaves a link containing the old text. Recreate it only after confirming the intended replacement:

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.
rm -- /srv/www/current
ln -s /srv/releases/app-2026.10-retired /srv/www/current
readlink -f /srv/www/current

For a production release path, an inspected replacement command may be safer than a remove-then-create gap, because a separate removal briefly leaves no link. Whichever method you choose, verify the destination and test the consuming service.

Use symlinks safely in shell scripts

Protect pathnames

  • Quote every variable expansion: "$link", not $link.
  • Use -- before path operands for commands that support it.
  • Use test -L to examine the link entry and test -e to test whether its target resolves.
  • Do not assume that a name ending in a slash is a symlink; a trailing slash can cause pathname traversal into a directory target.

Validate before forcing replacement

Before using -f in automation, verify that the destination is the expected kind of object and that the new target belongs to an approved directory. Use ls -ld, readlink, and readlink -f as separate checks. If an existing destination is unexpectedly a regular file or directory, fail closed and require operator review rather than deleting it automatically.

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

Understand race and privilege concerns

Checking a path and changing it are separate operations. Between the check and the replacement, another process with write access could change the directory entry. Run deployment steps with the least privilege that can update the intended parent directory, restrict write access to that directory, and avoid constructing link names from untrusted input. A symlink can redirect a privileged process to a sensitive location if the process follows a path in a writable directory.

Confirm which ln you have

The option set described above is from GNU Coreutils 9.11 documentation and the Linux ln(1) manual. Other Unix implementations can differ, especially for long options and replacement behavior. On the server where a script will run, check ln --help and the local manual page, and test the command in a non-production directory before deploying it.

Troubleshoot common failures

“File exists”

The destination name already exists. Inspect it with ls -ld and determine whether it is the intended link, a different symlink, a regular file, or a directory. Use plain ln -s when replacement should be refused; use -i, -b, or a validated -f workflow only when that policy is deliberate.

The link displays the wrong destination

Run readlink -- LINK_NAME. If the text is relative, resolve it from the directory containing the link. Recreate it from the correct location or use ln -s --relative with the intended source and destination. Do not fix a relative-path error by blindly converting it to an absolute path; first decide whether the tree must remain relocatable.

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

readlink -f fails

At least one component does not resolve, is inaccessible, or belongs to an unmounted filesystem. Compare the stored text from readlink with the actual directory layout, inspect each parent directory, and check mounts and permissions. A dangling link itself is permitted; the failure indicates that the complete path is not currently canonicalizable.

A service cannot follow a link

Confirm the service account can traverse every parent directory and read or enter the resolved target. Check mandatory access-control policies, container or chroot mount visibility, and whether the service resolves paths inside a different filesystem namespace. A link that works in an administrator’s shell may still be unavailable to a confined service.

Removing the link appears to remove data

Check whether the command operated on the link entry or on a path reached through it. Use ls -ld and readlink before changing anything, and avoid recursive options. rm -- LINK_NAME and unlink -- LINK_NAME remove the named symlink; they do not remove its target.

Operational checklist

  • Write the command as ln -s TARGET LINK_NAME; target first, link name second.
  • Choose absolute or relative storage based on relocation and mount requirements, not habit.
  • For relative links, calculate from the link’s parent directory or use GNU --relative.
  • Inspect with ls -l and readlink; resolve with readlink -f or realpath.
  • Remember that a dangling link can be created successfully but will fail when followed.
  • Before replacement, validate both the existing destination and the new target.
  • Use -i, -b, -f, and -T only when their operational effects are understood.
  • Remove a link with rm -- LINK_NAME or unlink -- LINK_NAME, never with recursive deletion merely because it points to a directory.
  • Find stale links with find PATH -xtype l -print and review each result before repair or deletion.
  • Confirm GNU-specific options against the server’s local ln implementation.

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.

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