30 Essential Linux Ops Commands Every Engineer Should Know
This guide presents 30 of the most frequently used Linux commands for operations engineers, organized into seven categories and illustrated with real‑world scenarios, parameter examples, safety warnings, and step‑by‑step usage tips to help you manage files, monitor systems, handle processes, diagnose networks, control users, compress data, and manage services.
1. File and Directory Operations
The article starts with the ls command for listing directory contents, showing common options such as -l, -a, -lt, and -lh. It demonstrates how to verify a missing file error with ls -la. The cd and pwd commands are covered, including shortcuts like cd - and pwd -P for navigating between directories and resolving symbolic links.
# List files with details
ls -l
# Show hidden files
ls -a
# Change to /etc directory
cd /etc
# Print current directory (resolved)
pwd -PCreating directories with mkdir is explained, highlighting -p for parent directories and -m for setting permissions. The dangers of rm -rf / are warned, and safe deletion practices such as confirming paths with ls before rm are recommended.
# Create nested directories
mkdir -p /data/app/logs/run
# Remove a directory safely after moving it
mv /data/backup_2024 /tmp/backup_2024_$(date +%Y%m%d)
rm -rf /tmp/backup_2024_20240101Copying and moving files with cp and mv are shown, including options like -r, -p, -u, and -i. A log‑rotation example uses mv to rename a log file and kill -HUP to make Nginx reopen it.
# Rename current log and signal Nginx
mv /var/log/nginx/app.log /var/log/nginx/app.log.$(date +%Y%m%d)
kill -HUP $(cat /var/run/nginx.pid)2. Text Processing and Viewing
Common utilities cat, less, head, tail, grep, awk, sed, wc, sort, and uniq are introduced with typical options. The article stresses using less +F for live log tailing and shows how to count lines with wc -l. Advanced grep usage includes recursive search, file‑type filters, and binary‑file exclusion.
# Show first 20 lines of a file
head -n 20 /etc/passwd
# Follow a log file interactively
less +F /var/log/app.log
# Recursive grep for "error" in .log files
grep -r "error" /var/log/*.log --include="*.log"
# Count unique IPs in Nginx access log
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -203. System Information and Monitoring
Tools such as top, htop, vmstat, iostat, netstat / ss, df, du, and free are covered. The article explains interpreting top fields, using htop shortcuts, and recognizing high
vmstat ror wa values as CPU or I/O bottlenecks. Disk usage is examined with df -h and du -sh, and memory details with free -h and the meaning of the available column.
# Show CPU‑intensive processes
top -b -n 1 | head -20
# Check I/O wait percentage
vmstat 1 5
# List open network sockets
ss -tlnp
# Display filesystem usage
df -h
# Show memory summary
free -h4. Process Management
The article compares ps aux and ps -ef, shows sorting by CPU or memory, and demonstrates filtering with grep. It explains terminating processes with pkill, kill, and killall, including signal options like SIGTERM, SIGKILL, and SIGHUP. Job control commands jobs, bg, and fg are illustrated for moving tasks between foreground and background.
# List all processes sorted by CPU usage
ps aux --sort=-%cpu | head -10
# Gracefully restart Nginx
kill -HUP $(cat /var/run/nginx.pid)
# Send SIGKILL to a stubborn process
kill -9 1234
# Move a stopped job to background
bg %15. Network Diagnostics
Connectivity testing uses ping with count and interval options. Route tracing with traceroute (or tracert on Windows) is shown, as is DNS lookup with nslookup and dig. The versatile nc (netcat) is used for port checks, file transfer, and reverse shells. HTTP interactions are demonstrated with curl (GET, POST, headers, authentication, redirects) and wget for downloads, including background and resume options. Finally, ip commands manage interfaces, addresses, and routes.
# Ping Google DNS 4 times
ping -c 4 8.8.8.8
# Trace route to a host
traceroute 8.8.8.8
# Query A record for example.com
dig +short www.example.com
# Test TCP port 22 on a server
nc -zv 192.168.1.100 22
# Download a file with curl and follow redirects
curl -L -O https://example.com/file.tar.gz
# Add a static route
ip route add 10.0.0.0/8 via 192.168.1.16. User and Permission Management
Creating, modifying, and deleting users and groups is covered with useradd, usermod, userdel, and groupadd. Permission changes use chmod (numeric and symbolic), chown, and chgrp. The article highlights special bits (SUID, SGID, sticky) and safe practices such as using chmod +x only when execution is required. Privilege escalation with sudo is explained, including checking sudo rights and configuring password‑less execution via visudo.
# Create a user with a home directory and bash shell
useradd -m -s /bin/bash alice
# Add alice to the sudo group
usermod -aG sudo alice
# Change ownership of a directory
chown alice:developers /opt/project
# Give execute permission to a script
chmod +x deploy.sh
# Run a command as root without a password (visudo entry)
# alice ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart nginx7. Compression and Archiving
Archive creation with tar (plain, gzip, bzip2, xz) is shown, including exclusion patterns and incremental backups. Simple file compression uses gzip, bzip2, and xz. Zip archives are created with zip and extracted with unzip. The article compares compression speed and ratio for each format.
# Create a gzipped tarball
tar -czf backup.tar.gz /data/project
# Extract a tar.xz archive to /tmp
tar -xJf archive.tar.xz -C /tmp
# Zip a directory recursively, excluding logs
zip -r archive.zip /var/www -x "*.log"
# List contents of a zip file
unzip -l archive.zip8. System Services and Log Management
Service control with systemctl (start, stop, restart, reload, enable, disable) and status inspection is described. Log access uses journalctl with filters for unit, priority, time range, and real‑time follow. Log rotation is configured via logrotate, with an example for Nginx logs that rotates daily, keeps 14 files, compresses, and signals Nginx to reopen logs.
# Restart nginx and view its logs
systemctl restart nginx
journalctl -u nginx -f
# Rotate nginx logs (logrotate config snippet)
/var/log/nginx/*.log {
daily
rotate 14
compress
missingok
notifempty
create 0640 www-data adm
sharedscripts
postrotate
[ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
endscript
}9. Troubleshooting Path
The article provides step‑by‑step checklists for high CPU load, memory exhaustion, disk‑space shortage, and network connectivity problems. Each checklist combines commands such as uptime, top, ps, free, df, du, ping, traceroute, and log inspection with journalctl. It also lists common log file locations for different distributions.
# CPU overload investigation
uptime
top -b -n 1 | head -20
ps aux --sort=-%cpu | head -10
# Memory shortage investigation
free -h
ps aux --sort=-%mem | head -10
# Disk space investigation
df -h
du -sh /* 2>/dev/null | sort -h
# Network connectivity investigation
ping -c 4 8.8.8.8
traceroute 8.8.8.8
ss -tlnp10. Summary and Best Practices
The guide concludes that mastering these 30 commands empowers Linux operations engineers to perform file manipulation, text processing, system monitoring, process control, network debugging, user management, data archiving, and service administration efficiently. Recommended best practices include verifying actions with ls or cat before destructive commands, consulting man pages, chaining commands with pipelines, scripting repetitive tasks, always checking logs first during incidents, and backing up configurations before changes.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
