Symbolic links let you reference files and directories from multiple locations without duplicating data. They act as pointers that redirect to the original file or folder, which makes them useful for organising complex directory structures and maintaining backwards compatibility when you move files.
You will create symbolic links using the ln command, verify they point to the correct target and remove them when no longer needed.
The ln command with the -s flag creates a symbolic link. The -s flag specifies a soft link rather than a hard link, which allows the link to point to directories and cross filesystem boundaries.
cd command to move to the directory that will contain the symbolic link. For example, cd /var/www moves you to the web root directory.ln -s /path/to/target/directory /path/to/link-name
For example, to create a link called docs in your home directory that points to /usr/share/documentation, you would run:
ln -s /usr/share/documentation ~/docs
ls -l in the directory containing your new link. Symbolic links display with an arrow showing the target path:lrwxrwxrwx 1 user user 24 15 January 2025 docs -> /usr/share/documentation
The l at the start of the permissions string confirms this is a symbolic link. You can now access the target directory through the link name.
Linux does not provide a direct command to modify a symbolic link’s target. You need to remove the existing link and create a new one pointing to the updated location.
rm command followed by the link name. This removes only the link, not the target directory:rm /path/to/link-name
ln -s command with the new target path and the same link name:ln -s /path/to/new/target /path/to/link-name
The link now points to the new location. Any applications or scripts referencing the link name will automatically use the new target without requiring configuration changes.
Removing a symbolic link deletes only the pointer, not the target file or directory. This makes symbolic links safe to remove when you no longer need the reference.
rm command with the link path:rm /path/to/link-name
ls -l in the directory. The link name should no longer appear in the listing.Do not add a trailing slash when removing directory symbolic links. Running rm /path/to/link-name/ may attempt to delete the target directory contents rather than the link itself.
You can create symbolic links using absolute paths that start from the root directory or relative paths that reference locations from the current working directory. Absolute paths remain valid regardless of where you access the link from, which makes them more reliable for system-wide references. Relative paths work when the link and target maintain their positional relationship, but break if you move either component independently.
We recommend using absolute paths for symbolic links that will be accessed from multiple locations or referenced in automated scripts.
You can now create symbolic links to reference directories from multiple locations, update link targets by removing and recreating them, and delete links without affecting the original files. Symbolic links reduce duplication and make directory structures more flexible.
Review your symbolic links periodically to confirm they still point to valid targets. Broken links occur when the target directory is moved or deleted. See our guides on Linux file permissions and SSH access for your server for related server management tasks.
Our Linux VPS hosting gives you full root access to create and manage symbolic links across your server environment.
Get scalable resources with our VPS hosting with root access and optional software.
Get VPS HostingPerfect for websites and small businesses unlimited bandwidth with cPanel hosting.
Get cPanel Hosting