Operations 11 min read

Linux Command Cheat Sheet: Essential Commands for Server Operations

A practical cheat sheet organizing essential Linux commands by scenario—file navigation, log analysis, process management, network and disk monitoring, compression, and permissions—with concrete examples and safety tips for daily server operations.

Code Farmer Manor Chronicle
Code Farmer Manor Chronicle
Code Farmer Manor Chronicle
Linux Command Cheat Sheet: Essential Commands for Server Operations

File & Directory Navigation

Directory navigation relies on cd and ls. Two high-value flags: ls -lh – detailed listing with human-readable sizes ls -lt – sort by modification time, newest first (ideal for "what changed recently?")

pwd                          # current directory
cd /var/log                  # change directory (~ home, .. parent, - previous)
ls -lh                       # detailed + human sizes (alias ll)
ls -lt                       # sort by mtime descending
mkdir -p a/b/c               # create nested directories recursively
cp -r dir1 dir2              # copy directory recursively
mv old.txt /tmp/             # move or rename

Warning: rm -rf has no recycle bin; a wrong path is catastrophic. Always ls to confirm before deleting, and verify variables are not empty when constructing paths.

Terminal shortcuts that boost efficiency:

Tab                # complete commands/paths (double-tap for candidates)
Ctrl + R           # search command history (most underrated)
Ctrl + L           # clear screen (same as clear)
history            # show history; !123 reruns entry 123
man ls             # full manual; ls --help for brief

Logs & Text Search

80% of production troubleshooting involves logs. Never cat large files; use this combo:

head -n 20 app.log           # first 20 lines
tail -n 100 app.log          # last 100 lines
tail -f app.log              # follow new lines (essential)
tail -f app.log | grep ERROR # follow and filter (standard combo)
less app.log                 # paged view; q to quit, /keyword to search
wc -l app.log                # count lines

Key grep flags worth memorizing: -c – count matches only -v – invert match (exclude) -n – show line numbers -r – recursive directory search -i – case-insensitive

File discovery uses find:

grep -rn "TIMEOUT" /etc/nginx   # recursive with line numbers
grep -c ERROR app.log            # count matching lines
grep -v "^#" config.conf         # view config, skip comments
find /var/log -name "*.log"      # find by name
find /home -name "*.json" -mtime -1  # modified within 1 day

Pipes and redirections (six symbols): | – pipe: left output becomes right input > – overwrite file >> – append to file 2>&1 – merge stderr into stdout && – run next only if previous succeeds || – run next only if previous fails

Most common patterns: python app.py > app.log 2>&1 – capture both stdout and stderr to log ./build.sh && ./deploy.sh – deploy only if build succeeds

Process Management

ps aux | grep python         # find processes (pipe filter is standard)
top                          # dynamic resource monitor; q to quit
kill 12345                   # graceful termination (try first)
kill -9 12345                # force kill (last resort)
pkill -f "gunicorn"          # kill by command name pattern
nohup python app.py &        # run in background, survive terminal exit
jobs / fg                    # list background jobs / bring to foreground

Best practice: Always try kill PID first to allow graceful cleanup. kill -9 denies the process a chance to release resources. For long-running services, use systemd instead of relying on nohup.

Network & Disk

Network toolkit: ping – test connectivity curl – send HTTP requests ss – inspect listening ports systemctl – manage services

curl -I https://example.com                 # headers only
curl -X POST -H "Content-Type: application/json" \
  -d '{"a":1}' http://localhost:8000/api  # POST example
ss -tlnp | grep 3306                      # check if port 3306 is listening (preferred)
ip addr                                   # show interface IPs
systemctl status nginx                    # service status

Disk toolkit: df -h – mount point usage du -sh – directory size summary free -h – memory usage

Disk full is the most common outage. Fixed three-step drill: df -h to identify the full mount point du -sh /* to drill down directory by directory

Clean the culprit

Log cleanup: use truncate -s 0 app.log (space released immediately). Plain rm on a file held open by a process does not free space. For Docker bloat: docker system prune.

df -h                      # mount point usage
du -sh /var/log            # size of /var/log
du -h --max-depth=1 /      # top-level directory sizes
truncate -s 0 app.log      # empty log file (space freed instantly)
docker system prune        # remove unused images/containers/cache

Compression, Permissions & Real-World Combos

tar

flags mnemonic: c reate, e x tract, z gzip, v verbose, f file (must be last).

tar -czvf dist.tar.gz dist/        # pack & gzip
tar -xzvf dist.tar.gz              # unpack
tar -xzvf dist.tar.gz -C /opt/     # unpack to specific dir
zip -r dist.zip dist/              # zip archive (unzip needed to extract)

Permission essentials: chmod +x deploy.sh – add execute bit chown -R deploy:deploy /opt/app – recursive owner change sudo – privilege escalation

Real-world command chains:

# Deploy static site: remove old, extract new
rm -rf /opt/dev-garden/dist && tar -xzvf dist.tar.gz -C /opt/dev-garden/

# Tail error log in real time
tail -f /var/log/nginx/error.log | grep -i error

# Find top CPU consumers
ps aux --sort=-%cpu | head -n 6

Top 10 High-Frequency Commands

ls -lh          # list files
tail -f xx.log  # follow log
grep -rn xx dir/ # search text recursively
find / -name xx # find file by name
ps aux          # list processes
kill -9 PID     # force kill process
df -h           # disk usage
free -h         # memory usage
ss -tlnp        # listening ports
tar -xzvf xx.gz # extract gzipped tar

Commands are infinite, but scenarios are finite. Master one lifesaver per category; two weeks of practice makes them second nature.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

operationsprocess managementlinuxcommand linesystem-administrationlog analysisgrepdisk usagecheat sheettar
Code Farmer Manor Chronicle
Written by

Code Farmer Manor Chronicle

A heart like drifting clouds, ever at ease; a mind like flowing water, free to roam.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.