Hey there. If you’ve ever felt that twinge of panic staring at a blank terminal prompt on a production server—yep, I’ve been there too. *Heart racing, coffee cold*—and you’re like “Wait… what was that command to check memory again?” Fear not. I’ve compiled my favorite, go-to Linux server commands into one narrative, drawing on years of late-night troubleshooting and accidental mis-typing (sorry, boss!). Grab your favorite mug, lean in, and let’s geek out over some CLI magic.
System Info: Getting the Lay of the Land
First things first: you gotta know what you’re working with. Think of these commands as your server’s Tinder profile—swipe right if you like what you see.
uname -a
: Shows kernel name, version, architecture, and hostname. Quick and dirty. It’s like asking, “Hey, who even are you?”lsb_release -a
orcat /etc/os-release
: Distro details—Ubuntu, CentOS, or some indie distro no one’s heard of.hostnamectl
: Modern twist onuname
, plus static vs. transient hostname. Useful when you’ve got 17 servers all named “web01” and need context.free -m
&grep MemTotal /proc/meminfo
: Memory peek. I once panicked thinking my app was leaking RAM, only to discover Docker’s cache doing its thing. Facepalm.more /proc/cpuinfo
orgetconf LONG_BIT
: CPU cores and bitness. Handy before you compile that monster open-source project.
Pro tip: wrap these in a small shell function—call it sysinfo()
—and you’ll be golden. I did that once, and life’s never been the same.
Process & Resource Monitoring: Who’s Hogging Your Server?
Ever had a mysterious spike in CPU? An SQL query gone rogue? These commands are your detective kit:
top
(or my personal fave,htop
): Real-time process view. Hit F to sort by CPU or M for memory. Watch that %CPU climb and sweat a little.ps aux | grep yourapp
: Snapshot of processes. Great for scripting alerts. I once used a tiny script that emailed me when a rogue Python script hit >80% CPU—saved my night.pmap PID
: Dive into a process’s memory map. Fancy, right? Sorts out shared vs. private memory.iostat -xd
: Disk I/O stats. If your database feels sluggish, this is where you start.iftop
ornethogs
: Live network traffic. See which IP is munching your bandwidth.
FWIW, mixing watch -n 2 'df -h'
with a gentle coffee sip is pure bliss. It’s like having a mini-dashboard rolling in your terminal.
File & Directory Operations: Your Digital Toolbox
Commands you’ll run a gazillion times:
ls -alh
: Show hidden files with human-readable sizes. Don’t forget theh
!cd /var/www/html
&pwd
: Navigate directories and confirm your current R★P.cp -r src/ dest/
&mv oldname newname
: Copy or move. *Yes, I once accidentally mv’d /etc to /tmp and nearly cried.*rm -rf /path/to/junk
: Deletes recursively. *Use with extreme caution.* If you’re me, you’ll alias it totrash
.mkdir -p /new/project/{src,bin,docs}
: Fuss-free multi-folder creation. Trust me, saves keystrokes.find / -name '*.log' -mtime +7 -exec rm {} \;
: Auto-clean logs older than a week. *Log bloat is real, folks.*
Note: I once set that find
command in a cron job—until I realized it nuked more than logs. Rookie move. 😅
User & Permission Management: The Gatekeepers
Multi-user servers demand tight control:
whoami
&groups
: Confirm your identity and group affiliations.useradd devops
&passwd devops
: Create new user and set a password.usermod -aG sudo devops
: Give sudo powers. Beware—sudo is like giving someone the keys to the kingdom.chmod 754 script.sh
&chown root:root script.sh
: Tweak permissions and ownership. Remember: 7 = rwx, 5 = r-x, 4 = r–.visudo
: Safest way to edit sudoers. One syntax error here… well, let’s just say you’ll be in single-user rescue mode fast.
Real talk: I once spent hours debugging permission issues before realizing I had an uppercase ‘X’ vs. lowercase ‘x’ typo in my chmod. So painful.
Firewall & Network Security: Locking Down the Gates
In 2025, you can’t skip firewall configuration. If iptables isn’t your jam, firewalld
likely is:
systemctl start firewalld
&firewall-cmd --state
: Firewalld basics.firewall-cmd --zone=public --add-port=22/tcp --permanent
&--reload
: Open SSH port. Simple.- Zone-based rules: trust, public, internal. I usually create a “web” zone for HTTP/HTTPS only.
- For deeper dives, check out Practical firewalld Configuration Guide. It’s my bible for firewall nuances.
OH—and yes, don’t forget to whitelist your office IP. You. Will. Get. Locked. Out.
Package Management: Installing & Updating Software
Depending on your distro:
sudo apt update && sudo apt upgrade
(Debian/Ubuntu) – my daily ritual before coffee.sudo yum install nginx
ordnf install httpd
(RHEL/CentOS/Fedora) – because that web server won’t install itself.rpm -ivh package.rpm
&rpm -e package
– when direct RPM handling is unavoidable.- Tip: always check
yum list installed | wc -l
orapt list --installed | wc -l
to gauge bloat.
FWIW, I learned the hard way that mixing apt and dpkg on the same system is a recipe for broken dependencies. *Don’t do it.*
Archiving & Compression: Keeping It Tidy
Dumping backups? Migrating data? These are your pals:
tar -zcvf archive.tar.gz /path/to/dir
– gzip + tar combo. Simple.tar -xjvf archive.tar.bz2
– bzip2 compression.gzip filename
&gunzip filename.gz
: single-file ops.du -sh *
&du -ah /var/log | sort -rh | head -n 10
– find space hogs. Life-changing when disk’s at 99%.
I once had a server crash because /home filled up with ancient backups. These commands? Would’ve saved me from midnight pager duty.Disk & Partition Management: Growing Your Filesystem
Cloud servers often start with tiny disks. Here’s how to expand:
lsblk
&fdisk -l
: Identify disks and partitions.sudo growpart /dev/xvda 1
: Extend partition (with cloud-init growpart).sudo resize2fs /dev/xvda1
orxfs_growfs /mount/point
: Resize filesystem.- Pro tip: run
e2fsck -f
first on ext4. Better safe than sorry.
Bonus: sync && echo 3 > /proc/sys/vm/drop_caches
frees pagecache. Use sparingly, as it can hobble performance.
Swap Management: Tuning Your Memory
Swap can save your butt when RAM runs dry:
fallocate -l 8G /swapfile
&chmod 600 /swapfile
.mkswap /swapfile
&swapon /swapfile
.sysctl vm.swappiness=60
: Tweak swappiness. I prefer ~30 for database servers—keeps them using RAM first.- Add to
/etc/fstab
for permanence.
Real-world aside: I set the wrong swappiness value once and my DB started swapping like crazy—latencies shot through the roof until I fixed it.
Troubleshooting & Tips: Real-Life War Stories
Here’s where I get real:
- Accidental Deletes: Always alias
rm
tomv
to a~/trash
folder. Fewer tears. - Network Outage: Keep a serial console handy if SSH goes poof. Trust me.
- Permission Hell: Use
getfacl
andsetfacl
for complex ACLs—avoids “but I thought I was root!” screams. - Firewall Lockout: Schedule an automatic rollback of firewall rules after 5 minutes. Saved me on multiple occasions.
Further Reading
Craving more? Dive into these two FoxDooTech server deep dives:
- Linux Server Network Troubleshooting: Six Common Scenarios and Solutions
- Practical firewalld Configuration Guide: Master Linux Firewall Management
Wrapping Up
There you have it: my personal, slightly messy, hopefully helpful toolkit of Linux server commands and tips. No sugarcoating—this is the real deal, forged by midnight crises and coffee-fueled debugging sessions. Bookmark it, copy those snippets, and remember: the command line is powerful, but you’re the real force behind it. Now go forth, conquer your servers, and maybe show this guide to a friend who’s stuck in “command amnesia.” Cheers!