Linux provides various methods for managing files and directories efficiently. One of the most powerful mechanisms is the use of links, which allow files to have multiple references without duplicating their content. There are two primary types of links:
Symbolic Links (Soft Links)
Hard Links
This article explores how symbolic links function, their advantages, and how they differ from hard links.
What Are Symbolic Links?
Symbolic links, also known as soft links or symlinks, are special file references that point to another file or directory. These links enable multiple names for the same file, ensuring flexibility and version control.
Introduction
Linux stores system settings and scripts in plain text files. To safely view these files in the terminal, the less
command offers a reliable solution—allowing you to scroll and search without modifying anything.
Using the less Command
Basic syntax:
less filename
Example: view user account info:
less /etc/passwd
To exit less
, press q
.
What Is Text?
Text files contain raw character data, often encoded with ASCII—where each letter or symbol maps to a numeric value. Unlike word processor formats (e.g., DOC, ODT), plain text doesn't include layout or style instructions.
This simplicity makes text files ideal for system configuration, scripting, and portability. Even tools like Notepad in Windows rely on this universal format.
Navigating with less
Command | Action |
Page Up / b | Scroll up one page |
Page Down / Space | Scroll down one page |
↑ | Scroll up one line |
↓ | Scroll down one line |
G | Jump to end of file |
1G / g | Jump to beginning |
/search | Find a term |
n | Find next match |
h | View help screen |
q | Quit less |
Why less Is Better than more
less
improves upon the older more
command by allowing both forward and backward scrolling, pattern searching, and responsive navigation.
This led to the humorous Unix motto: “Less is more!”
Conclusion
The less
command is a fundamental tool for viewing Linux text files—especially those used in configuration and scripting. Its user-friendly navigation and powerful search features make it a go-to utility for command-line professionals and beginners alike.
A symbolic link appears in a directory listing like this:
lrwxrwxrwx 1 root root 11 2018-08-11 07:34 libc.so.6 -> libc-2.6.so
Here, libc.so.6 is a symbolic link that directs programs to libc-2.6.so. Any application that requests libc.so.6 will actually use the file libc-2.6.so.
Why Are Symbolic Links Useful?
Symbolic links simplify file management, especially for programs and shared libraries. Consider the following scenario:
A program relies on a file named foo.
The file foo frequently updates to newer versions (foo-2.6, foo-2.7, etc.).
Instead of modifying every program that references foo, we create a symbolic link that always points to the latest version.
With symbolic links:
Programs continue accessing foo, even when its version updates.
Developers can easily switch between different versions without renaming files.
If a bug appears in foo-2.7, reverting back to foo-2.6 is simple—just update the symbolic link instead of modifying multiple program references.
Hard Links vs. Symbolic Links
While symbolic links provide flexible references, hard links offer another type of file association.
Key Differences Between Symbolic and Hard Links
Feature | Symbolic Link | Hard Link |
Reference Type | Points to the target file's path | Points directly to the file's data |
Existence Dependency | Breaks if the target file is deleted | Remains valid even if the original file is deleted |
Cross-Partition Support | Can span multiple file systems | Works only within the same partition |
File Size | Small—stores only the path reference | Same as original file—multiple names reference the same data |
Conclusion
Symbolic and hard links are essential tools for efficient file management in Linux.
Symbolic links allow easy referencing, version control, and flexible navigation.
Hard links provide a permanent association with file data, ensuring stability even if the original reference is removed.