Explore plans starting at ₹699/mo →
VPS & Servers

Essential Linux Commands Every Server Administrator Should Know

S
ServerRaja
9 min read
#Troubleshooting#Linux#Tutorial#Guide#Best Practices#System Administration
Essential Linux Commands Every Server Administrator Should Know

Effective server administration requires fluency with the Linux command line. Whether you are managing a single VPS or a fleet of servers, these commands form the foundation of daily operations, troubleshooting, and maintenance tasks.

File and Directory Management

ls - List Directory Contents

The ls command is the most frequently used command. Essential variations: - ls -la: show all files including hidden, with detailed permissions, ownership, and timestamps - ls -lh: human-readable file sizes (KB, MB, GB) - ls -lt: sort by modification time (newest first) - ls -lS: sort by file size (largest first)

cd - Change Directory

Navigation basics: - cd /path/to/directory: absolute path navigation - cd .. : move up one directory - cd ~ : move to home directory - cd - : return to previous directory

cp, mv, rm - Copy, Move, Delete

cp -r source/ destination/: recursively copy directories mv old-name new-name: rename or move files and directories rm -rf directory/: forcefully remove a directory and all contents

CAUTION: rm -rf is irreversible. Always double-check the path before executing. Consider using rm -i for interactive confirmation on production servers.

find - Search for Files

find is extremely powerful for locating files: - find / -name "*.log" -type f: find all .log files - find /var -size +100M: find files larger than 100 MB in /var - find /tmp -mtime +7 -delete: delete files in /tmp older than 7 days - find / -perm -4000: find SUID files (security audit)

grep - Search File Contents

The grep command searches for patterns within files: - grep -r "error" /var/log/: recursively search for "error" in log files - grep -i "warning" logfile.log: case-insensitive search - grep -c "404" access.log: count matching lines - grep -v "debug" logfile.log: show lines NOT matching (invert) - journalctl | grep -i error: search system journal for errors

Process Management

ps - Process Status

ps aux: show all running processes with detailed information ps aux | grep nginx: find specific processes ps aux --sort=-%mem | head: show top memory-consuming processes ps aux --sort=-%cpu | head: show top CPU-consuming processes

top and htop - Real-Time Process Monitoring

top provides a live, updating view of system processes. Key interactions: - Press 1: show per-CPU core utilization - Press M: sort by memory usage - Press P: sort by CPU usage - Press k: kill a process by PID

htop is an enhanced alternative with a more user-friendly interface. Install it with: sudo apt install htop (or sudo dnf install htop)

systemctl - Service Management

systemctl is the primary tool for managing system services: - systemctl status nginx: check service status - systemctl start/stop/restart nginx: control services - systemctl enable/disable nginx: configure auto-start at boot - systemctl list-units --type=service: list all services - systemctl daemon-reload: reload after unit file changes

journalctl - System Journal

journalctl queries the systemd journal (system logs): - journalctl -u nginx -f: follow nginx logs in real-time - journalctl --since today: show today's log entries - journalctl -p err: show only error-level messages - journalctl --disk-usage: check journal storage usage

System Information

free - Memory Usage

free -h: show memory usage in human-readable format free -h -s 5: update every 5 seconds

Key values to watch: - total: total installed RAM - used: actively used memory - available: memory available for new applications - swap used: any swap usage indicates potential memory pressure

df - Disk Usage

df -h: show disk usage for all mounted filesystems df -h /home: show usage for a specific mount point

Monitor disk usage proactively. A full disk can cause database corruption, application failures, and logging interruptions.

du - Directory Size

du -sh /var/log: show total size of /var/log du -sh /var/* | sort -rh | head: show largest directories in /var

du is essential for investigating disk space issues and identifying which directories are consuming the most space.

Networking

ss - Socket Statistics

ss has replaced netstat as the primary network debugging tool: - ss -tlnp: show listening TCP ports with process names - ss -ulnp: show listening UDP ports - ss -s: show socket statistics summary - ss -tnp: show established TCP connections

ip - Network Configuration

ip addr show: display network interfaces and IP addresses ip route show: display routing table ip link show: display interface status (up/down)

ping and traceroute

ping target-host: test connectivity and measure latency traceroute target-host: show the network path to a destination

These are the first tools to use when diagnosing network connectivity issues.

Disk and I/O

iostat - I/O Statistics

iostat -x 1: show detailed disk I/O statistics, updating every second

Key metrics: - %util: disk utilization percentage (consistently above 80% indicates a bottleneck) - await: average I/O wait time in milliseconds - r/s, w/s: read and write operations per second

Practical Combinations

Experienced administrators chain commands together: - ps aux | grep java | grep -v grep | awk '{print $2}': find Java process PIDs - tail -f /var/log/nginx/access.log | grep 502: watch for 502 errors in real-time - df -h | awk '$5 > 80 {print}': alert on filesystems over 80% full - find /var/log -name "*.gz" -mtime +30 -delete: clean up old compressed logs

Conclusion

Mastering these commands gives you the tools to manage servers effectively, diagnose problems quickly, and automate routine tasks. As you gain experience, you will discover increasingly powerful combinations and patterns. The command line is the most efficient interface for server administration, and fluency with these tools is essential for any infrastructure professional.

Essential Linux Commands for Server Admins | ServerRaja