Essential Linux Commands Every Server Admin Should Know
You've just SSH'd into a fresh server, and the first thing you need to do is check what's actually running. You try to run a command, but it's not found. You need to see what processes are consuming CPU, but you don't know where to look. You need to restart a service, but you're not sure which command to use. This is where the real work of server administration begins.
Linux commands are your primary interface with the system. Every task you perform—deploying applications, monitoring performance, troubleshooting issues, managing users—relies on these commands. This guide covers the essential commands you'll use daily, with practical examples you can adapt to your own environment.
Understanding the Command Line Basics
Before diving into specific commands, it helps to understand how the command line works. The terminal accepts commands in this format:
- command: The actual program you want to run (like
ls,grep,ps) - options: Flags that modify the command's behavior (like
-l,-a,-r) - arguments: The targets the command operates on (like filenames, directories, processes)
Options typically start with a hyphen (-) or double hyphen (--). Some commands accept both single and multiple options combined, like ls -la (list all files, including hidden ones, in long format).
File and Directory Management
Listing Files and Directories
The ls command lists directory contents. The most commonly used options are:
This shows all files (including hidden ones starting with .) in long format, including permissions, owner, size, and modification time.
Shows files in human-readable format (KB, MB, GB instead of bytes).
Sorts files by modification time, with the most recently modified files at the top.
Navigating Directories
Change to a directory:
Navigate to the parent directory:
Go to the home directory:
Go to the previous directory:
Creating and Removing Directories
Create a new directory:
Create multiple nested directories at once:
The -p flag creates parent directories as needed.
Remove a directory:
This only works for empty directories. To remove a directory and its contents:
Warning: The -r (recursive) and -f (force) flags remove everything without confirmation. Use with caution.
Viewing File Contents
Display the entire file:
Display file contents with line numbers:
View a file in a paginated format (useful for large files):
Press q to exit.
Display the first 10 lines:
Display the last 10 lines:
Follow a growing log file in real-time:
Press Ctrl+C to stop.
Searching for Text in Files
Search for a pattern in a file:
Search recursively in all files in a directory:
Count matching lines:
Case-insensitive search:
Process Management
Viewing Running Processes
List all running processes:
This shows all processes with user, PID, CPU usage, memory usage, and command details.
Find a specific process:
Use pgrep for a cleaner output:
Monitoring Processes in Real-Time
View real-time process statistics:
Press q to exit. Use h for help.
Monitor specific processes:
htop provides a more interactive interface with color-coded processes and the ability to sort by different metrics.
Killing Processes
Find the PID of a process:
Kill a process by PID:
Force kill a process:
The -9 signal is the most aggressive and should be used as a last resort.
Kill all processes matching a pattern:
Managing Services
List all services:
Check the status of a service:
Start a service:
Stop a service:
Restart a service:
Reload a service without dropping connections:
Enable a service to start on boot:
Disable a service from starting on boot:
System Information and Monitoring
Getting System Information
Display system information:
Show kernel version:
Display CPU information:
Show memory usage:
Show disk usage:
Show mounted file systems:
Monitoring System Resources
Display real-time resource usage:
Monitor CPU and memory usage:
The 1 argument updates every second.
Check disk I/O statistics:
Monitor network connections:
Or use the newer ss command:
User and Permission Management
Managing Users
Create a new user:
The -m flag creates a home directory, and -s sets the default shell.
Set a password for the user:
Delete a user:
Delete a user and their home directory:
Managing User Groups
Create a new group:
Add a user to a group:
List all groups:
File Permissions
View file permissions:
Change file ownership:
Change file permissions:
The numeric format represents permissions as follows:
- 4 (read)
- 2 (write)
- 1 (execute)
For directories, add execute permission to allow traversal:
Network Configuration and Troubleshooting
Checking Network Connections
Show all network connections:
Or use ss:
Check if a port is listening:
Or:
Testing Network Connectivity
Ping a host:
Check DNS resolution:
Or use dig:
Test connectivity to a specific port:
Or use telnet:
Viewing Network Statistics
Show network interface statistics:
Or use ifconfig:
Show routing table:
Or:
Package Management
Debian/Ubuntu Systems
Update package lists:
Upgrade all packages:
Install a package:
Remove a package:
Remove a package and its configuration files:
Search for a package:
Red Hat/CentOS Systems
Update package lists:
Install a package:
Remove a package:
Search for a package:
Practical Walkthrough: Setting Up a Production Web Server
Let's walk through a complete setup of a production web server using these commands. This example uses Ubuntu, but the concepts apply to other Linux distributions.
Step 1: Update the System
First, ensure your system is up to date:
The sudo command runs the command with superuser privileges. The && operator runs the second command only if the first succeeds.
Step 2: Install Nginx
Install the web server:
Start and enable Nginx:
Verify it's running:
Step 3: Configure the Firewall
Allow HTTP and HTTPS traffic:
Enable the firewall:
Step 4: Deploy Your Application
Create a directory for your application:
Set ownership:
Create a simple HTML file:
Add your HTML content and save with Ctrl+O, Enter, then Ctrl+X.
Step 5: Configure Nginx
Create a new server block:
Add the following configuration:
Enable the site:
Test the configuration:
Reload Nginx:
Step 6: Set Up SSL with Let's Encrypt
Install Certbot:
Obtain and install SSL certificate:
Follow the prompts to accept the terms and enter your email address.
Step 7: Verify Everything is Working
Check if Nginx is listening:
Or:
Test your website in a browser at http://yourdomain.com.
Common Troubleshooting Commands
Finding Missing Commands
If you try to run a command and get "command not found":
This shows where the command is located. If it returns nothing, the command isn't installed.
Checking Disk Space
If you're running out of disk space:
Find large files:
This shows the top 10 largest directories in the current location.
Checking for Running Processes
If a service isn't working:
Check if a process is running:
If nothing is returned, the process isn't running.
Checking Logs
View system logs:
View application logs:
Essential Command Shortcuts
Master these keyboard shortcuts to work more efficiently:
Ctrl+C: Cancel the current commandCtrl+D: Exit the terminalCtrl+L: Clear the screenCtrl+R: Search command historyTab: Auto-complete commands and filenamesCtrl+A: Move cursor to the beginning of the lineCtrl+E: Move cursor to the end of the lineCtrl+U: Clear the current lineCtrl+K: Cut everything from cursor to end of lineCtrl+Y: Paste the last cut text
Conclusion
These commands form the foundation of Linux server administration. You'll use them daily, whether you're deploying applications, monitoring performance, or troubleshooting issues. The key is to understand not just what each command does, but when and why you'd use it.
Start by practicing these commands in a safe environment. Create a virtual machine or use a cloud server with a fresh installation. Build a simple web application and deploy it using these commands. As you gain confidence, you'll naturally learn more advanced commands and techniques.
Platforms like ServerlessBase can simplify many of these tasks by providing managed services and automated deployments, but understanding the underlying commands remains essential for troubleshooting and optimization. When something goes wrong, you'll need to know how to inspect logs, check processes, and manage services manually.
The command line is a powerful tool that, once mastered, gives you complete control over your server. Take time to practice each command, understand its options, and build a mental model of how Linux systems work. This knowledge will serve you throughout your career as a server administrator or DevOps engineer.
Next Steps
Now that you know the essential commands, consider learning:
- Shell scripting to automate repetitive tasks
- Advanced file management with
findandxargs - Log analysis with
grep,awk, andsed - Network troubleshooting with
tcpdumpandwireshark - Container management with Docker and Kubernetes
Each of these areas builds on the fundamentals covered here and will expand your ability to manage and troubleshoot Linux systems effectively.