How to Create a Symbolic Link (Symlink) in Linux
DodaTech
1 min read
In this tutorial, you'll learn about How to Create a Symbolic Link (Symlink) in Linux. We cover key concepts, practical examples, and best practices.
The Problem
You want a file or folder to appear in multiple places without duplicating it. Symbolic links (symlinks) are references that point to the original file.
Quick Fix
Create a symlink to a file
ln -s /original/file.txt /path/to/link.txt
Now /path/to/link.txt behaves exactly like /original/file.txt.
Create a symlink to a directory
ln -s /original/folder /path/to/folder
Check what a symlink points to
ls -la /path/to/link
Expected output:
lrwxrwxrwx 1 user user 20 Jun 15 10:00 link.txt -> /original/file.txt
The l at the start means it's a symlink. The -> shows the target.
Overwrite an existing symlink
ln -sf /new/target/file.txt /path/to/link.txt
Hard Links vs Symlinks
| Type | Command | Works across filesystems? | Points to |
|---|---|---|---|
| Symlink (soft) | ln -s |
Yes | A path |
| Hard link | ln |
No | The same inode (data block) |
Hard links can't link to directories. Use symlinks for directories.
Fixing Broken Symlinks
# Find broken symlinks
find . -xtype l
# Recreate a broken symlink
rm broken-link
ln -s /correct/path broken-link
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro