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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

On Ubuntu 16.04 and 18.04, create a symbolic link with:

ln -s TARGET LINK_NAME

TARGET is the file or directory the link should reference; LINK_NAME is the new directory entry. For example:

sudo ln -s /var/www/example/current/public /var/www/example/public

The GNU ln utility works on both releases. However, Ubuntu 16.04 reached standard security end of life in April 2021 and Ubuntu 18.04 in May 2023. Canonical’s lifecycle information lists limited Ubuntu Pro or legacy coverage, but upgrading to a supported release is the preferred long-term solution: Canonical Ubuntu release cycle.

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.

What a symlink is

A symbolic link (symlink) is a filesystem entry that stores a pathname to another file or directory. It has its own directory entry and inode, but pathname resolution follows the stored target path when a program opens it.

#1 Best Overall
Sale
YOTUO 500GB External Hard Drive, Portable Storage Expansion HDD, USB 3.0 & USB-C for PC, Mac, Desktop, Laptop, Smartphone, PS4, Xbox One, Xbox 360, Office & Game Black
  • 【Versatile Storage Expansion – For Gaming, Work & Everyday Use】 Running out of space on your PS5 or Xbox Series X/S? This external hard drive lets you store and play PS4 / Xbox One games directly, instantly freeing up your console’s internal storage for next‑gen titles. At the same time, it handles work file backups, media libraries, and cross‑device data transfers with ease. One drive, all your needs. *(Note: PS5 / Xbox Series X|S games cannot be run or stored directly from the external hard drive. However, by offloading your PS4 / Xbox One games, you can free up valuable space for newer titles.)*
  • 【Patented Silicone Sleeve – Data Protection You Can Count On】 Worried about drops? We’ve got you covered. The patented built‑in silicone sleeve acts like a shock‑absorbing armor, cushioning your drive against bumps and falls. Whether it’s important work documents, precious family photos, or hard‑earned game saves, your data deserves this level of protection.
  • 【Plug & Play, Compatible with Computers & Consoles】 No complicated setup—just plug in and go. Works seamlessly with Windows, Mac, and Linux computers, as well as PS4, PS5, Xbox One, and Xbox Series X/S. Process files at the office, back up data at home, or enjoy gaming in your downtime—one drive handles all your devices, simply and hassle‑free.
  • 【USB 3.0 Ultra‑Fast Transfer – No More Waiting】 Tired of watching progress bars crawl? With USB 3.0 speeds up to 5Gbps, large files transfer in seconds. Whether you’re moving work documents, transferring hundreds of gigs of games, or backing up a year’s worth of photos, you get more done in less time.
  • 【Sleek, Lightweight, and Ready to Go】 Weighing just 0.16 kg—lighter than a can of soda—this compact drive features a stylish mirror‑and‑frosted finish. Toss it in your bag and go, whether you’re heading to the office, visiting a friend for a gaming session, or giving a presentation on the road.
  • Symlinks can point to files or directories.
  • They can refer to paths on another filesystem, provided that filesystem is mounted and accessible.
  • They may point to a target that does not yet exist.
  • They become dangling when the target is moved or deleted.
  • A relative target is interpreted from the directory containing the symlink, not from the shell’s current directory.

The Ubuntu ln documentation describes these semantics in the Bionic man page.

Symlink versus hard link

Property Symbolic link Hard link
Command ln -s ln
References A pathname The target inode
Directories Yes Normally no
Crosses filesystems Yes No, in ordinary use
Target deleted Becomes dangling Data remains while another hard link exists
Typical use Alternate paths and release switching Additional names for the same file data

Hard links normally require an existing target and are restricted for directories. Symlinks are pathname indirection, not merely graphical shortcuts.

Before you create one

  • Use a terminal.
  • You need read and search (execute) permission through the target path.
  • You need write permission in the directory that will contain the link.
  • Use sudo for system-owned locations such as /etc, /usr/local, /var/www, and /opt.
  • Back up or inspect production paths before replacing them.

Put sudo before the command, not around one of its path arguments:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo ln -s /opt/myapp/current /var/www/myapp

Create a symlink

File example

mkdir -p ~/symlink-demo
printf 'hellon' > ~/symlink-demo/original.txt
ln -s ~/symlink-demo/original.txt ~/symlink-demo/link.txt

Inspect the directory:

ls -l ~/symlink-demo

You should see a pattern like link.txt -> /home/username/symlink-demo/original.txt. The argument order is always:

ln -s TARGET LINK_NAME

Directory example

mkdir -p ~/symlink-demo/real-directory
ln -s ~/symlink-demo/real-directory ~/symlink-demo/directory-link
touch ~/symlink-demo/directory-link/test.txt
ls -l ~/symlink-demo/real-directory

test.txt appears in the real directory because the directory symlink is followed. For predictable scripts, use explicit paths and avoid relying on ambiguous trailing-slash behavior.

Rank #2
YOTUO 1TB External Hard Drive, Portable Storage Expansion HDD, USB 3.0 & USB-C for PC, Mac, Desktop, Laptop, Smartphone, PS4, Xbox One, Xbox 360, Office & Game, Black
  • 【Versatile Storage Expansion – For Gaming, Work & Everyday Use】 Running out of space on your PS5 or Xbox Series X/S? This external hard drive lets you store and play PS4 / Xbox One games directly, instantly freeing up your console’s internal storage for next‑gen titles. At the same time, it handles work file backups, media libraries, and cross‑device data transfers with ease. One drive, all your needs. *(Note: PS5 / Xbox Series X|S games cannot be run or stored directly from the external hard drive. However, by offloading your PS4 / Xbox One games, you can free up valuable space for newer titles.)*
  • 【Patented Silicone Sleeve – Data Protection You Can Count On】 Worried about drops? We’ve got you covered. The patented built‑in silicone sleeve acts like a shock‑absorbing armor, cushioning your drive against bumps and falls. Whether it’s important work documents, precious family photos, or hard‑earned game saves, your data deserves this level of protection.
  • 【Plug & Play, Compatible with Computers & Consoles】 No complicated setup—just plug in and go. Works seamlessly with Windows, Mac, and Linux computers, as well as PS4, PS5, Xbox One, and Xbox Series X/S. Process files at the office, back up data at home, or enjoy gaming in your downtime—one drive handles all your devices, simply and hassle‑free.
  • 【USB 3.0 Ultra‑Fast Transfer – No More Waiting】 Tired of watching progress bars crawl? With USB 3.0 speeds up to 5Gbps, large files transfer in seconds. Whether you’re moving work documents, transferring hundreds of gigs of games, or backing up a year’s worth of photos, you get more done in less time.
  • 【Sleek, Lightweight, and Ready to Go】 Weighing just 0.16 kg—lighter than a can of soda—this compact drive features a stylish mirror‑and‑frosted finish. Toss it in your bag and go, whether you’re heading to the office, visiting a friend for a gaming session, or giving a presentation on the road.

Link several targets into a directory

ln -s /opt/tools/tool-a /opt/tools/tool-b /usr/local/bin/

Or specify the destination first:

sudo ln -s -t /usr/local/bin /opt/tools/tool-a /opt/tools/tool-b

Both forms are documented in the Ubuntu Bionic ln manual.

Absolute and relative symlinks

Type Example Strengths Risks
Absolute ln -s /srv/releases/app-2026-08-18 /srv/app/current Easy to read; independent of the caller’s current directory Breaks if the directory tree moves
Relative cd /srv/app && ln -s ../releases/app-2026-08-18 current The tree can move together; useful for deployable bundles Breaks if only part of the tree moves; path calculation must be correct

On both releases, ln can calculate a relative target:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ln -sr /srv/releases/app-2026-08-18 /srv/app/current

A relative link is resolved from the symlink’s containing directory. It is more relocatable only when that relative directory structure remains intact.

Inspect and verify a link

ls -ld /path/to/link
readlink /path/to/link
readlink -f /path/to/link
stat /path/to/link
stat -c '%N' /path/to/link
namei -l /path/to/link
  • ls -ld describes the directory entry itself, including a directory symlink.
  • readlink prints the stored target text.
  • readlink -f resolves the complete canonical path when the target can be resolved; see the Ubuntu readlink manual.
  • stat -c '%N' displays the link without silently treating it as its target.
  • namei -l shows each path component and its permissions.

Distinguish the link from its target:

test -L /path/to/link && echo "It is a symlink"
test -e /path/to/link && echo "Its target currently exists"

A dangling symlink satisfies -L but fails -e.

Replace or update a symlink

A symlink is not edited in place. For an important path, inspect, remove, recreate, and verify:

readlink /srv/app/current
rm /srv/app/current
ln -s ../releases/app-2026-08-19 /srv/app/current
readlink -f /srv/app/current

A common deployment shortcut is:

ln -sfn ../releases/app-2026-08-19 /srv/app/current

-f removes an existing destination and -n prevents a symlink-to-directory destination from being treated as a directory. The result depends on what already exists, so do not treat ln -sf as universally risk-free. For high-consequence paths, use the explicit sequence above.

Rank #3
Sale
500GB External Hard Drive,USB 3.0 and USB-C Storage Expansion Mobile HDD
  • Versatile Storage for Gaming, Work & Daily Use: This portable external drive expands console storage to store and play last-gen console games directly, freeing up console internal space for new games. It also supports file backup, media storage and cross-device data transfer for office and daily use.(Please Note: PS5 / Xbox Series X|S games cannot be run or stored directly from the external hard drive. However, by offloading your PS4 / Xbox One games, you can free up valuable space for newer titles.)
  • Reinforced Silicone Outer Casing for Daily Data Safeguard: Built with customized integrated silicone protective casing for enhanced outer protection. The buffer silicone structure relieves impact from accidental bumps, knocks and short-distance drops during daily carrying and use. It offers stable protection for office documents, personal photo albums, local game progress files and other private digital data, lowering daily data damage risks caused by physical collision.
  • Universal Plug-and-Play Compatibility for Multi-device Use: No extra driver download or complex configuration required for daily use. This external storage drive delivers stable connection and normal read-write performance across mainstream desktop, laptop and game console systems, including Windows, Mac, Linux operating systems and PS4、PS5、Xbox One和Xbox Series X/S mainstream home game consoles. Switch freely between office file processing, home data backup and leisure gaming use without cumbersome setup steps.
  • Standard USB 3.0 High-speed Interface for Efficient File Transfer: Equipped with standard USB 3.0 transmission interface, supporting stable transfer speed up to 5Gbps to shorten large-file waiting time. It accelerates batch game file migration, raw imagealbum backup and large office folder transmission, improving file arrangement and backupefficiency for gaming enthusiasts, office workers and daily home users.
  • Ultra-light Compact Body with Exquisite Daily Carry Design: Adopts lightweight integrated body structure, weighing only 0.3lb for effortless portable carrying. Combined with premium sleek and frosted dual-texture outer surface, the minimalist appearance fits daily outing, business trip and party gaming scenarios. It can be easily placed in backpacks, laptop bags and handbags for convenient outdoor and off-site data use anytime.

Remove a symlink safely

ls -ld /path/to/link
readlink /path/to/link
rm /path/to/link

unlink /path/to/link is another way to remove the link itself. Neither command removes the target when the supplied path is the symlink.

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

Do not use recursive deletion for this task:

rm -rf /path/to/link

A trailing slash, as in rm /path/to/directory-link/, asks the system to treat the path as a directory and can change the operation. For a directory symlink, use the path without the trailing slash and verify with test -L.

Find and repair broken links

To list symlinks that cannot be followed:

find -L /path/to/search -type l

For a report that preserves unusual filenames:

find /path/to/search -type l -print0 |
while IFS= read -r -d '' link; do
    if [ ! -e "$link" ]; then
        printf 'Broken: %s -> %sn' "$link" "$(readlink "$link")"
    fi
done

Diagnose a “No such file or directory” result with:

ls -ld /path/to/link
readlink /path/to/link
readlink -f /path/to/link
namei -l /path/to/link
  1. Check whether the target was moved or renamed.
  2. Recalculate relative paths from the link’s parent directory.
  3. Check every parent directory for missing search permission.
  4. Check spelling and case.
  5. Confirm that a required mount is available.
  6. Check whether the link was created inside a chroot or container whose filesystem has different paths.

Symlink loops

If links eventually point back to themselves, commands may fail with Too many levels of symbolic links. Use readlink and namei -l to identify the cycle, then remove or correct one directory entry rather than recursively deleting the path.

Permissions, services, and security

A symlink grants no permissions. Access still depends on the target, execute/search permission on every parent directory, mount options, the identity of the process, and controls such as AppArmor or SELinux where enabled.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
YOTUO 750GB External Hard Drive, Portable Storage Expansion HDD, USB 3.0 & USB-C for PC, Mac, Desktop, Laptop, Smartphone, PS4, Xbox One, Xbox 360, Office & Game Black
  • 【Versatile Storage Expansion – For Gaming, Work & Everyday Use】 Running out of space on your PS5 or Xbox Series X/S? This external hard drive lets you store and play PS4 / Xbox One games directly, instantly freeing up your console’s internal storage for next‑gen titles. At the same time, it handles work file backups, media libraries, and cross‑device data transfers with ease. One drive, all your needs. *(Note: PS5 / Xbox Series X|S games cannot be run or stored directly from the external hard drive. However, by offloading your PS4 / Xbox One games, you can free up valuable space for newer titles.)*
  • 【Patented Silicone Sleeve – Data Protection You Can Count On】 Worried about drops? We’ve got you covered. The patented built‑in silicone sleeve acts like a shock‑absorbing armor, cushioning your drive against bumps and falls. Whether it’s important work documents, precious family photos, or hard‑earned game saves, your data deserves this level of protection.
  • 【Plug & Play, Compatible with Computers & Consoles】 No complicated setup—just plug in and go. Works seamlessly with Windows, Mac, and Linux computers, as well as PS4, PS5, Xbox One, and Xbox Series X/S. Process files at the office, back up data at home, or enjoy gaming in your downtime—one drive handles all your devices, simply and hassle‑free.
  • 【USB 3.0 Ultra‑Fast Transfer – No More Waiting】 Tired of watching progress bars crawl? With USB 3.0 speeds up to 5Gbps, large files transfer in seconds. Whether you’re moving work documents, transferring hundreds of gigs of games, or backing up a year’s worth of photos, you get more done in less time.
  • 【Sleek, Lightweight, and Ready to Go】 Weighing just 0.16 kg—lighter than a can of soda—this compact drive features a stylish mirror‑and‑frosted finish. Toss it in your bag and go, whether you’re heading to the office, visiting a friend for a gaming session, or giving a presentation on the road.

A link that works in your shell may fail for Apache, Nginx, systemd, or cron because those services run as different users. For example:

sudo ln -s /srv/app/shared/uploads /var/www/app/uploads

The web server must still be able to traverse /srv, /srv/app, and /srv/app/shared, and access the target with the required read or write permissions.

Do not let root-owned scripts blindly follow links in directories writable by untrusted users. A link can be replaced between validation and use, creating a symlink attack; use controlled ownership and safer filesystem operations for security-sensitive workflows.

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

Useful layouts

Versioned application releases

sudo ln -s /srv/releases/app-2026-08-18 /srv/app/current

Applications can use /srv/app/current while deployments switch that link to another release. Relative links are useful when the entire application tree is moved together.

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

Configuration enablement

sudo ln -s /etc/example/sites-available/site.conf 
           /etc/example/sites-enabled/site.conf

This “available/enabled” arrangement is an application convention, not a universal Ubuntu rule. Validate the application’s configuration before reloading its service.

Best Value
NRICO 500GB Ultra Slim Portable External Hard Drive USB3.0 HDD
  • Metal Design: Merely 0.51 inch thick. ABS Plastic+Aluminum external hard drive, with aluminum finish-style. Shockproof, anti-pressure, ultra slim and portable
  • System Compatibility: Compatible with MAC, Windows 2000/7/8/10, Vista, Linux, and Android operating systems
  • Improve PC Performance: Powered by USB 3.0 technology, this USB hard drive is much faster than - but still compatible with - USB 2.0 backup drive, allowing for super fast transfer speed at up to 5 Gbit/s
  • Plug and Play: With no software to install, just plug it in and the drive is ready to use
  • Package Includes: 1 x Portable Hard Disk, 1 x USB 3.0 cable, user's manual, 3-Year manufacturer warranty with free technical support service

Stable command path

sudo ln -s /opt/tools/tool-a /usr/local/bin/tool-a

Users can invoke the tool through a stable path while the actual installation remains under /opt.

Copying, backups, and alternatives

Decide whether a backup should preserve the link or copy the target’s contents. For cp, -P preserves symlinks and -L follows them; recursive defaults can vary by invocation, so check the local manuals:

man cp
man tar

Preserve links when reproducing a filesystem layout; dereference them only when you intentionally want the target data.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Copying: avoids dangling links and can be self-contained, but duplicates data and can become stale.
  • Bind mounts: expose a directory at another path without a symlink, but require mount privileges and persistence through /etc/fstab or a systemd mount unit.
  • Hard links: retain the inode when one name is removed, but generally cannot target directories or cross filesystems.

Choose a symlink when a stable alternate pathname, release switch, configuration toggle, or cross-filesystem reference is useful. Avoid it when software does not support links, a self-contained copy is required, a mount or container boundary is unreliable, or an untrusted user can control the path.

Command quick reference

Command or option Purpose
ln -s TARGET LINK Create a symbolic link
ln -sr TARGET LINK Create a relative symbolic link
ln -sfn TARGET LINK Common forced replacement shortcut; inspect directory cases carefully
ln -t DIR TARGET... Create links inside a specified directory
readlink LINK Show stored target text
readlink -f LINK Resolve a canonical target path
test -L LINK Check that the path itself is a symlink
test -e LINK Check that the resolved target exists
rm LINK or unlink LINK Remove the symlink entry
find -L ROOT -type l Find dangling symlinks

For option details on Ubuntu 16.04 and 18.04, consult the release-specific manuals: Xenial ln and Bionic ln.

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.