- 1How to Create a File in Linux
- 2How to Rename a File in Linux
- 3How to Copy a File in Linux
- 4How to Move a File in Linux
- 5How to Delete a File in Linux
- 6How to Create a Directory in Linux
- 7How to Delete a Directory in Linux
- 8How to Copy Directories Recursively in Linux
- 9Delete Directories Recursively in Linux
- 10How to View Hidden Files in Linux
- 11How to Create a Hidden File in Linux
- 12How to Create a Hidden Directory in Linux
- 13How to Find Files in Linux Using find Command
- 14Find Files in Linux Using locate Command
- 15How to View File Contents Using cat in Linux
- 16How to View File Contents Using less in Linux
- 17View File Contents Using the more Command in Linux
- 18Compare Files Using diff Command in Linux
- 19Compare Files in Linux Using cmp Command
- 20Check File Type in Linux with file Command
- 21Create Symbolic Links with ln -s in Linux
- 22How to Archive Files Using tar Command in Linux
- 23Compress Files with gzip in Linux – Beginner Tutorial
- 24How to Compress Files Using bzip2 in Linux
- 25Compress Files in Linux Using zip Command
- 26Extract Compressed Files using tar in Linux
- 27Extract ZIP Files on Linux with unzip
- 28How to Extract .gz Files using gunzip in Linux
How to Create Symbolic Links Using ln -s
How to Create Symbolic Links Using ln -s
Hey there! 👋 If you're new to Linux, you've probably seen the term "symbolic link" or "symlink" floating around. But what exactly is it? And why would you want to use it?
In simple terms, a symbolic link is like a shortcut or alias to another file or directory. It doesn't hold the actual content, but it *points* to something else—just like how a desktop shortcut opens a file from another location.
🧠 Why Use Symbolic Links?
- To avoid duplicating large files or folders
- To organize files across multiple locations
- To make configurations cleaner and more maintainable
🛠️ Basic Syntax
ln -s [target] [link_name]
Let’s break this down:
- [target] — This is the original file or directory you want to link to.
- [link_name] — This is the name of the symbolic link you’re creating.
📁 Example 1: Linking a File
Let’s say we have a file called report.txt
in our Documents folder, and we want to create a symbolic link to it on the Desktop.
cd ~/Desktop
ln -s ~/Documents/report.txt report-link.txt
Now we can check the link:
ls -l report-link.txt
lrwxr-xr-x 1 user group 25 Jul 2 10:00 report-link.txt -> /home/user/Documents/report.txt
The arrow (->
) confirms that report-link.txt
is a symlink pointing to report.txt
.
📂 Example 2: Linking a Directory
You can do the same for a directory. For example, link a project folder to your home directory:
ln -s ~/projects/myapp ~/myapp-link
ls -l ~/myapp-link
lrwxr-xr-x 1 user group 20 Jul 2 10:15 myapp-link -> /home/user/projects/myapp
🧹 To Remove a Symbolic Link
Just delete it like a regular file:
rm report-link.txt
Don’t worry — this won’t touch the original file.
⚠️ Common Pitfall: Relative Paths
If you use a relative path instead of an absolute one, the link will break if you move it to a different location. Always prefer absolute paths when in doubt.
✅ Recap
- Use
ln -s
to create symbolic (soft) links - They act like shortcuts, saving space and effort
- Work with both files and directories
- Use absolute paths for stability
That’s it! 🎉 Now you know how to use symbolic links to simplify your file and directory management in Linux. Go ahead and try it out!
Next Topic ⮕How to Archive Files Using tar Command in Linux
Comments
Loading comments...