9 Linux Tricks
9 Linux Tricks
Anyone can navigate a file system. But a true System Engineer knows how to manipulate process memory, recover lost sessions, and create disk space out of thin air when the server hits 100% utilization at 3 AM.
These are not just commands; they are survival tools. Here are 9 advanced Linux tricks to elevate you from a user to a master :)

Table of Contents
- Ghost Hunting: Finding deleted files consuming disk space (
lsof) - Time Travel: Moving a running process into a screen (
reptyr) - The X-Ray Machine: Debugging processes without logs (
strace) - Config Espionage: Reading a running process’s environment (
/proc) - The Panic Button: Instant disk space for Root (
tune2fs) - SSH Turbo Mode: Connection multiplexing (
ControlMaster) - The Quick Fix: correcting typos instantly (
^old^new) - Modern Network Analysis:
netstatis dead, long livess - Muscle Memory:
sudo !!and!$
1. Ghost Hunting: lsof +L1
Scenario: df -h says disk usage is 100%, but you just deleted gigabytes of log files. Reason: If a process (like Apache or Postgres) is still writing to a file you deleted, the OS doesn't free the space (inode). It becomes a "zombie" file.
The Fix:
lsof +L1
# Look for files marked as (deleted) but still held by a PID.
# You must reload/restart that specific PID to free the space.
2. Time Travel: reptyr
Scenario: You started a long script, it’s been running for 4 hours, but you forgot to start a screen or tmux session. You need to disconnect, but closing the terminal will kill the script.
The Fix: Use reptyr to "steal" the process and reparent it to a new screen.
# 1. Background the process: Ctrl+Z, then type 'bg'
# 2. Disown it from current shell: 'disown <PID>'
# 3. Open a new screen/tmux and pull it in:
reptyr <PID>
3. The X-Ray Machine: strace
Scenario: A process is hanging. No logs. No CPU usage. Is it waiting for network? Is it permission denied? The Fix: Don’t guess. Watch the system calls in real-time.
strace -p <PID>
# You will see exactly what the kernel is doing:
# open(), connect(), read()...
# This is the ultimate debugging weapon.
4. Config Espionage: /proc Filesystem
Scenario: A developer claims, “It works on my machine,” but the production service fails. You suspect it picked up the wrong DB password or API key from the environment. The Fix: Read the memory of the running process directly.
cat /proc/<PID>/environ | tr '\0' '\n'
# This dumps every environment variable the process was started with.
# No more guessing.
5. The Panic Button: tune2fs
Scenario: Production is down. Disk is 100% full. You can’t even tab-complete commands because there is zero space for temp files. The Fix: Linux reserves 5% of blocks for the root user by default. In an emergency, you can set this to 0% to instantly gain GBs of space.
tune2fs -m 0 /dev/sdX
# Warning: Set it back to 5% once you clean up!
6. SSH Turbo Mode: ControlMaster
Scenario: Running Ansible or opening multiple tabs to the same server is slow because of the SSH handshake. The Fix: Enable connection multiplexing. The first connection authenticates; subsequent connections slide through the existing tunnel instantly.
# In your ~/.ssh/config:
Host *
ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h-%p
ControlPersist 600
7. The Quick Fix: ^old^new
Scenario: You typed a long command with a typo. systemctl restart nginxx The Fix: Don't hit the up arrow and scroll back.
^nginxx^nginx
# Bash automatically runs: systemctl restart nginx
8. Modern Network Analysis: ss
Scenario: You are still using netstat. The Fix: netstat is deprecated, slow, and truncates output. ss (Socket Statistics) talks directly to the kernel and is blazing fast.
ss -tulpn
# -t: TCP, -u: UDP, -l: Listening, -p: Process, -n: Numeric
# See everything listening on your server in milliseconds.
9. Muscle Memory: sudo !! and !$
sudo !!: You typed a command but forgotsudo.- Action: Type
sudo !!(runs the last command as root). !$: You created a directory and now want to go into it.
mkdir -p /var/www/html/project/v2 cd !$
# '!$' expands to the last argument of the previous command
Conclusion
These tricks aren’t just for showing off; they are for saving the day when standard tools fail. Master these, and the terminal becomes an extension of your mind, not just a black screen.
Which of these “dark arts” do you use the most? Let me know in the comments.
← PostgreSQL Blog