Symbolic (Soft) Links in Linux — Creating Flexible File References¶
A Symbolic Link (Soft Link or Symlink) is a special type of file that points to another file or directory by its pathname. Unlike a hard link, a symbolic link has its own inode and acts like a shortcut. Symbolic links are widely used in Linux for application deployments, version management, configuration sharing, and storage management.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand symbolic links
- Create soft links
- Understand relative and absolute symlinks
- Identify broken symbolic links
- Compare hard links and symbolic links
- Manage symlinks in production
- Troubleshoot common symlink issues
Prerequisites¶
Before starting this lesson, complete:
- Module 1 – Linux Fundamentals
- Module 2 – Command Line Essentials
- Module 3 – Text Processing
- Module 4 Lessons 1–2
Why Learn Symbolic Links?¶
Suppose your application is deployed here:
Later you deploy:
Instead of changing every script, update a single symbolic link:
Now every service automatically uses the latest version.
This is exactly how many production deployments work.
What is a Symbolic Link?¶
A symbolic link is a special file that stores the path to another file or directory.
It behaves like a shortcut.
Syntax:
Linux View¶
Unlike a hard link, the symbolic link points to the pathname, not the inode.
Create a Symbolic Link¶
Create a file.
Create a symbolic link.
Display:
Output:
Notice:
- Starts with
l - Shows the target using
->
Read Using the Link¶
Output:
The symbolic link behaves like the original file.
Modify Through the Link¶
Append data.
Display original.
Output:
View Link Details¶
Output:
Display inode information.
Example:
Notice:
- Different inode numbers
- Different file types
- The symbolic link stores only the target path
Delete the Original File¶
Now:
Output:
The symbolic link still exists, but its target is gone.
This is called a broken symbolic link.
Broken Symbolic Link¶
View:
Output:
Although the link exists, it no longer points to a valid file.
Find broken symbolic links.
Remove a Symbolic Link¶
Delete the link.
or
Only the link is removed.
The original file (if it exists) is unaffected.
Symbolic Links to Directories¶
Create:
Create a symbolic link.
Display.
Output:
Navigate:
This works exactly like entering the original directory.
Absolute vs Relative Symbolic Links¶
Absolute Path¶
Stores:
Relative Path¶
Stores:
Which One Should You Use?¶
| Type | Best For |
|---|---|
| Absolute | Fixed system paths |
| Relative | Portable projects and repositories |
Many software projects prefer relative symbolic links because they continue working if the project directory is moved.
Hard Link vs Symbolic Link¶
| Hard Link | Symbolic Link |
|---|---|
| Same inode | Different inode |
| Points to file data | Points to pathname |
| Cannot span filesystems | Can span filesystems |
| Usually cannot link directories | Can link directories |
| Continues working if original filename is removed | Becomes broken if target is removed |
View Link Target¶
Output:
Display the absolute target.
Find All Symbolic Links¶
Find broken symbolic links.
Common Commands¶
Create:
View:
Read target.
Delete.
Real Production Examples¶
Current application release.
NGINX configuration.
Java installation.
Python versions.
Shared storage.
Production Perspective¶
Symbolic links are heavily used in:
- Kubernetes deployments
- NGINX configuration
- Apache virtual hosts
- Docker volumes
- Java alternatives
- Python virtual environments
- Blue-Green deployments
- Rolling application upgrades
They allow applications to switch between versions without changing configuration files.
Hands-on Lab¶
Task 1¶
Create a file.
Task 2¶
Create a symbolic link.
Task 3¶
Display.
Task 4¶
Read the file through the symbolic link.
Task 5¶
Append data.
Task 6¶
Delete the original file.
Try reading the symbolic link.
Task 7¶
Find broken symbolic links.
Task 8¶
Remove the symbolic link.
Command Deep Dive¶
| Command | Purpose | Production Example |
|---|---|---|
ln -s | Create symbolic link | Deployments |
ls -l | Display link target | Troubleshooting |
readlink | Show target | Verification |
unlink | Remove link | Cleanup |
find -type l | Find symlinks | Audits |
find -xtype l | Find broken links | Maintenance |
Production Troubleshooting Scenario¶
Scenario
An application suddenly fails after a deployment.
Investigation:
- Verify the
currentsymbolic link. - Check if the target directory exists.
- Confirm the application points to the correct release.
- Update the symbolic link if necessary.
Commands:
A broken symbolic link is discovered after the old release directory was accidentally removed.
The fix:
The -n and -f options replace the existing link without affecting the target directory.
Best Practices¶
- Prefer symbolic links when linking directories.
- Use relative symbolic links inside projects for portability.
- Verify links after deployments.
- Remove broken symbolic links during maintenance.
- Use meaningful link names such as
current,latest, oractive.
Common Mistakes¶
❌ Deleting the target instead of the symbolic link.
✅ Always verify with:
before deleting files.
❌ Assuming a symbolic link stores the file itself.
✅ It stores only the target path.
❌ Using absolute symbolic links in portable projects.
✅ Relative links are often more resilient when moving directories.
Interview Questions¶
Beginner¶
- What is a symbolic link?
- Which command creates a symbolic link?
- How do you identify a symbolic link using
ls -l? - What happens if the target file is deleted?
Intermediate¶
- Explain the difference between hard and symbolic links.
- What is a broken symbolic link?
- How do you find all symbolic links?
- How do you display the target of a symbolic link?
Architect Level¶
- Why are symbolic links commonly used in application deployments?
- How do symbolic links support Blue-Green deployments?
- When would you use a relative symbolic link instead of an absolute one?
Summary¶
In this lesson, you learned:
- Creating symbolic links
- Reading and modifying files through symbolic links
- Relative vs absolute symbolic links
- Broken symbolic links
- Viewing link targets
- Production deployment use cases
Symbolic links provide flexible references to files and directories. They are widely used in Linux system administration, DevOps, and production environments to simplify configuration management and application deployments.
Key Takeaways¶
- A symbolic link is a special file that stores a pathname.
- Use
ln -sto create symbolic links. - Symbolic links have their own inode.
- If the target is removed, the symbolic link becomes broken.
- Symbolic links can point to directories and span different filesystems.
- They are commonly used for version management and deployment strategies.
What's Next?¶
Linux File Permissions — Understanding Read, Write, and Execute
In the next lesson, you'll learn:
- Reading permission strings
- User, Group, and Others
- Read, Write, and Execute permissions
- Numeric (octal) permission modes
- Directory permissions and production security patterns