From file twins to black holes — mastering Linux links and /dev
without melting your brain. Linux has some under-the-hood tricks that are ridiculously powerful once you get them.
Today we’re talking about links (hard and soft) and those strange /dev
files that look like folders but are actually gateways to your system’s hardware and magic devices.
Why Should You Care?
Ever copied a huge file just so you could keep a “backup” — only to realize you’ve just wasted half your disk space? Or stumbled across /dev/null
and thought, “What is this black hole doing in my computer?”
This article will turn you into a Linux wizard who knows how to link files like a pro and understand /dev
devices without feeling like you’re reading a sci-fi manual.
1. The ln
Command – Linking Without Copying
Think of ln
as your way of saying, “Hey, I want two names for the same thing” (hard link) or “Hey, I want a shortcut to that thing” (symbolic link).
Hard Links — The Identical Twins
A hard link is like giving someone a second name — they’re still the same person underneath.
In Linux terms:
- Both files share the same inode (the storage reference).
- Changing one changes both.
- Deleting one won’t destroy the data as long as the other still exists.
Example:
ln server.log server_backup.log
Now server.log
and server_backup.log
are basically the same file. You could edit server_backup.log
, and the changes magically appear in server.log
.
When to use:
- Keeping “backup” names without duplicating big files.
- Testing edits on one name while keeping the original filename intact.
Symbolic Links — The Shortcuts
A symbolic link (or symlink) is like a post-it note saying “The file you want is over there.”
- Uses a different inode.
- Stores the path to the target file, not the data itself.
- If the target moves or is deleted — link breaks.
Example:
ln -s /var/www/html/index.html homepage.html
Now homepage.html
is just a shortcut to index.html
. Move index.html
, and homepage.html
is useless.
When to use:
- Creating easy-to-type shortcuts for deeply buried files.
- Linking configuration files to one central place.
Useful Options for ln
--backup
→ makes a backup before overwriting.-f
→ force overwrite without asking.-i
→ asks for confirmation before overwriting.-s
→ create a symbolic link.-v
→ shows what’s happening (verbose mode).
2. /dev
— The Magical Hardware Closet of Linux
If /home
is your living room, /dev
is the secret storage room where all your hardware connections live. Inside, you’ll find “special files” that don’t store regular data — instead, they let the system talk to devices.
Block Devices — The Heavy Lifters
- Handle data in chunks (blocks).
- Think hard drives, SSDs, USB sticks.
- Appear as
/dev/sda
,/dev/sdb1
(sdb1 = first partition of the second drive).
When to use:
- Mounting new drives.
- Formatting or partitioning storage.
Character Devices — The Live Feed
- Handle data one character at a time.
- Examples: keyboards, serial ports, terminals (
/dev/tty
,/dev/ttyUSB0
).
Scenario:
Debugging a hardware issue? You might check /dev/ttyUSB0
to see if your device is even being recognized.
Special Character Devices — The Weird but Useful Tools
/dev/null
— The black hole of Linux. Anything you send here disappears forever.
Example:
command > /dev/null
(Runs a command but hides the output.)
/dev/zero
— Endless stream of zeros. Useful for overwriting data or creating dummy files.
Example:
head -c 100M /dev/zero > emptyfile.bin
/dev/urandom
— Endless stream of random data. Often used for cryptography or generating random passwords.
Example:
head -c 16 /dev/urandom | base64
Real-Life Linux Story
Once, I needed a “copy” of a 2GB log file to test some scripts, but my drive was almost full. Instead of duplicating the whole file, I made a hard link. Boom — instant “copy,” zero extra space used. Then, while writing a script, I dumped debug output to /dev/null
so my terminal stayed clean. My coworker thought I’d found some “magic command” — nope, just Linux doing its thing.
TL;DR
- Hard link → Same data, different names. Saves space, changes sync both ways.
- Symbolic link → Shortcut to a file path. Breaks if the file moves.
/dev
contains special files that represent hardware and system devices.
Cool /dev
tricks:
/dev/null
= delete output./dev/zero
= endless zeros./dev/urandom
= endless randomness.
Hard links are like identical twins who share the same brain, soft links are like friends who give directions to your house — and /dev/null
is that friend who nods while you talk but never actually listens