๐Ÿง Linux Lab

Bash one-liners, shell scripts, distro configs, and hard-won tips from daily Linux use.

ALL
BASH
FILESYSTEM
NETWORKING
SYSTEMD
PACKAGES
SECURITY
SCRIPTING
GAMING
Debian 12
Arch
Fedora
NixOS
Ubuntu
disk-hogs.sh โ€” find what's eating your disk
BASHFILESYSTEM
One-liners to quickly track down disk usage culprits. Run du as root so it can read all directories.
# Top 20 largest dirs from current location
du -ah . | sort -rh | head -20

# Show size of every dir in /var (great for finding log bloat)
du -sh /var/*/ | sort -rh

# Find files larger than 500MB anywhere on the system
find / -type f -size +500M -exec ls -lh {} \; 2>/dev/null

# Interactive: ncdu (install it, it's worth it)
apt install ncdu && ncdu /
harden-ssh.sh โ€” lock down SSH access
BASHSECURITY
Key SSH hardening steps after a fresh server install. Always test key auth in a separate session before disabling password login.
# 1. Generate a strong key on your LOCAL machine
ssh-keygen -t ed25519 -C "hornt3ch@$(hostname)"

# 2. Copy key to server
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@192.168.1.50

# 3. On the SERVER โ€” harden /etc/ssh/sshd_config
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
sed -i 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
echo "Port 2222" >> /etc/ssh/sshd_config

# 4. Restart SSH (keep current session open!)
systemctl restart sshd
my-service.service โ€” create a systemd service
SYSTEMDBASH
Template for creating a systemd unit file to run any script or app as a persistent service.
# /etc/systemd/system/myapp.service
[Unit]
Description=My Custom App
After=network.target

[Service]
Type=simple
User=hornt3ch
WorkingDirectory=/opt/myapp
ExecStart=/opt/myapp/run.sh
Restart=on-failure
RestartSec=5
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

# Reload, enable, and start it
systemctl daemon-reload
systemctl enable --now myapp
journalctl -u myapp -f  # follow logs
net-diag.sh โ€” network troubleshooting toolkit
BASHNETWORKING
Essential one-liners for diagnosing network issues on any systemd-based distro.
# Show all interfaces with IPs
ip -brief addr show

# What's listening on what port?
ss -tlnp

# Trace route to see where packets die
traceroute 1.1.1.1

# DNS lookup
dig hornt3ch.com @1.1.1.1

# Watch live network traffic on an interface
tcpdump -i eth0 -n -v port 80

# Test if a port is open (no nmap needed)
timeout 2 bash -c "cat < /dev/null > /dev/tcp/192.168.1.1/22" \
  && echo "OPEN" || echo "CLOSED"
linux-gaming-setup.sh โ€” Steam + Proton + GameMode
BASHGAMING
Get Steam + Proton-GE + GameMode + MangoHud running on Debian/Ubuntu. The combo that makes Linux gaming competitive.
# Enable 32-bit support (required for Steam)
dpkg --add-architecture i386
apt update

# Install Steam
apt install steam-installer

# Install GameMode and MangoHud
apt install gamemode mangohud

# Download latest Proton-GE
VER="GE-Proton9-20"
mkdir -p ~/.steam/root/compatibilitytools.d
curl -L "https://github.com/GloriousEggroll/proton-ge-custom/releases/download/$VER/$VER.tar.gz" \
  | tar -xz -C ~/.steam/root/compatibilitytools.d/

# Steam launch options to use it all:
# PROTON_USE_WINED3D=0 MANGOHUD=1 gamemoderun %command%
pkg-cheatsheet โ€” apt / dnf / pacman quick ref
PACKAGESBASH
Cross-distro package management cheat sheet. Same task, three package managers.
# โ”€โ”€โ”€ INSTALL โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
apt    install vim          # Debian/Ubuntu
dnf    install vim          # Fedora/RHEL
pacman -S vim               # Arch

# โ”€โ”€โ”€ UPDATE ALL โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
apt    update && apt upgrade
dnf    upgrade
pacman -Syu

# โ”€โ”€โ”€ SEARCH โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
apt    search htop
dnf    search htop
pacman -Ss htop

# โ”€โ”€โ”€ REMOVE + CLEAN โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
apt    autoremove --purge vim
dnf    autoremove vim
pacman -Rns vim
๐Ÿ’ก
Use !! and !$ to save keystrokes
!! repeats your last command โ€” so sudo !! re-runs it with sudo. !$ inserts the last argument of the previous command. Type mkdir /some/long/path then cd !$ to jump right in.
๐Ÿ”ต
Always alias your most-used commands
Add to ~/.bashrc: alias ll='ls -lahF --color=auto', alias gs='git status', alias update='sudo apt update && sudo apt upgrade -y'. Run source ~/.bashrc to reload without restarting.
โš ๏ธ
Never run rm -rf without double-checking the path
Use ls -la /path/to/thing first. Better: install trash-cli and alias rm to trash. The classic horror story is a stray space: rm -rf /home /user instead of /home/user.
โšก
Ctrl+R is your best friend โ€” reverse history search
Press Ctrl+R then start typing any part of a previous command. Keep pressing to cycle through matches. Install fzf to supercharge this with a proper fuzzy finder across your entire history.
๐Ÿ“‹
Use tmux so SSH sessions survive disconnects
Start with tmux new -s work. If you disconnect, tmux attach -t work picks up exactly where you left off. Key bindings: Ctrl+B D to detach, Ctrl+B % to split vertically.
โš ๏ธ
Check your /etc/fstab before rebooting after changes
A bad fstab entry will drop you into emergency mode. After editing, run mount -a to test all entries. Use UUIDs from blkid โ€” not device names like /dev/sdb1 which can change.
๐Ÿ”ง
journalctl is more powerful than you think
journalctl -u nginx -f follows a service. journalctl --since "1 hour ago" for time filtering. journalctl -p err for errors only. journalctl --vacuum-size=500M to trim log bloat.
๐Ÿง
Proton Experimental often works better than a numbered version
When a game doesn't run, try Proton Experimental first, then Proton-GE. Check ProtonDB.com for community-tested settings. PROTON_LOG=1 dumps a detailed log to your home directory.
๐Ÿ“
Use rsync instead of cp for large copies
rsync -avh --progress source/ dest/ gives progress and resumes on interruption. Add --delete to mirror. Add -n for a dry-run preview before committing.