Table of Contents
๐ง Introduction
In the world of DevOps, Linux is everywhereโfrom development environments and CI/CD runners to production servers and cloud infrastructure. Whether you’re deploying containers, configuring CI pipelines, or managing cloud instances, chances are you’re doing it on a Linux-based system.
For DevOps engineers, having a strong grasp of Linux commands is not just helpfulโit’s essential. These commands allow you to troubleshoot issues quickly, automate tasks efficiently, and maintain systems effectively.
In this post, weโll explore a curated list of essential Linux commands every DevOps engineer should know, categorized by their use case and practical value in real-world DevOps workflows.
๐งฐ System Information Commands
Before making any changes to a server or container, itโs important to know the system youโre working with. These commands help you gather key information about your Linux system:
| Command | Description |
|---|---|
uname -a | Displays system architecture, kernel version, and OS info. |
hostname | Shows the systemโs hostname. Useful in multi-node clusters. |
uptime | Tells you how long the system has been running. |
top / htop | Live display of running processes and resource usage. |
๐ง Example Use Case:
You log into a production EC2 instance to debug performance issues. Running top quickly shows that memory usage is maxed out due to a misconfigured process. You can act immediately to mitigate the impact.
๐ File and Directory Commands
Navigating the file system is a basic yet vital part of any DevOps workflow. Whether you’re modifying config files, reading logs, or moving scripts around, these commands are your bread and butter:
| Command | Description |
|---|---|
ls | Lists files and directories. Use ls -l for details. |
cd | Changes the current working directory. |
pwd | Prints the full path of the current directory. |
mkdir | Creates a new directory. |
rm | Deletes files (rm -rf deletes directories recursively). |
cp | Copies files and directories. |
mv | Moves or renames files/directories. |
find | Searches files by name, type, size, etc. |
tree | Visual representation of directory structure (install separately). |
๐ง Example Use Case:
While setting up a deployment script, you use find /var/www -name "*.log" to locate and clean up leftover log files from a previous release.
๐ File Permissions and Ownership
File permissions are crucial for system security and stability, especially when working in multi-user environments or deploying scripts to production.
| Command | Description |
|---|---|
chmod | Changes file permissions (e.g., chmod 755 file.sh). |
chown | Changes file ownership (e.g., chown user:group file). |
chgrp | Changes group ownership. |
umask | Sets default permission for new files. |
๐ง Example Use Case:
After deploying a new script via a CI pipeline, you use chmod +x deploy.sh to make it executable, and chown root:root deploy.sh to assign the proper owner.
๐ฆ Package Management
Different Linux distributions use different package managers. Knowing how to install, update, or remove software is key for server provisioning.
For Debian/Ubuntu:
| Command | Description |
|---|---|
apt update | Updates package lists. |
apt upgrade | Installs latest versions of packages. |
apt install nginx | Installs a package. |
apt remove nginx | Removes a package. |
For RHEL/CentOS:
| Command | Description |
|---|---|
yum install nginx / dnf install nginx | Installs packages. |
yum update | Updates all packages. |
rpm -qa | Lists all installed RPM packages. |
๐ง Example Use Case:
During provisioning, your script installs Docker and Git using apt install -y docker.io git, ensuring all build agents are properly configured.
๐ Text Processing Commands
DevOps work involves a lot of log reading, config editing, and data processing. These tools help extract valuable insights from text:
| Command | Description |
|---|---|
cat, less, more | Display file contents. |
head, tail | Show beginning/end of files. |
grep | Search for patterns in files. |
awk, sed | Stream editing and text transformation. |
cut, sort, uniq | Column filtering, sorting, deduplication. |
๐ง Example Use Case:
You monitor deployment logs with tail -f deploy.log | grep error to catch any real-time failures in your pipeline.
๐ Networking Commands
Diagnosing network issues is a day-to-day task in DevOps. These commands help you test connectivity, DNS, ports, and more:
| Command | Description |
|---|---|
ping google.com | Checks basic connectivity. |
curl / wget | Sends HTTP requests. |
netstat / ss | Shows active ports and connections. |
traceroute | Tracks route to a host. |
dig, nslookup | DNS lookup tools. |
๐ง Example Use Case:
While deploying an app, curl http://localhost:3000/health helps validate that your service is up and running correctly.
โ๏ธ Process and Service Management
Managing background services, checking process health, and restarting daemons are critical for uptime and reliability.
| Command | Description |
|---|---|
ps aux | Lists running processes. |
kill PID | Terminates a process. |
killall nginx | Kills all processes with name. |
nice / renice | Sets process priority. |
systemctl | Manages services (start, stop, restart). |
journalctl | Views system logs (e.g., journalctl -u nginx). |
๐ง Example Use Case:
After updating a config, use systemctl restart nginx and monitor logs via journalctl -u nginx -f.
๐งฎ Disk and Memory Usage
Running out of disk or memory can crash systems and pipelines. These commands help you keep an eye on resource consumption:
| Command | Description |
|---|---|
df -h | Shows disk space usage in human-readable format. |
du -sh * | Shows size of each item in current directory. |
free -m | Displays memory usage. |
vmstat | Reports system performance. |
iostat | Shows CPU and disk I/O (requires sysstat). |
๐ง Example Use Case:
Your CI runner is failing builds. You find with df -h that the disk is full and clear old Docker images to free space.
๐ Archiving and Compression
Useful for backups, file transfers, and packaging code, these commands help you archive and compress data effectively:
| Command | Description |
|---|---|
tar -czvf backup.tar.gz folder/ | Compress a directory. |
tar -xzvf backup.tar.gz | Extract an archive. |
zip -r archive.zip folder/ | Create a zip file. |
unzip archive.zip | Unpack a zip file. |
๐ง Example Use Case:
Before deploying a release, you archive the build folder with tar -czvf release.tar.gz dist/ for backup.
๐ Scripting and Automation Basics
Bash scripting is essential for automating tasks, especially in CI/CD pipelines or cron jobs.
Basic Elements:
#!/bin/bash
# Variables
ENV="prod"
# Conditional
if [ "$ENV" == "prod" ]; then
echo "Deploying to production"
fi
# Loop
for i in {1..3}; do
echo "Running test $i"
done
# Function
backup() {
tar -czf backup.tar.gz /var/www
}
Scheduling with Cron:
crontab -e
# Run backup at 2AM every day
0 2 * * * /home/ubuntu/backup.sh
๐ง Example Use Case:
You schedule automated backups with a Bash script and cron job to ensure daily snapshots of your app data.
๐งช Bonus: DevOps Tools Installed via Linux
Linux is the preferred platform for installing and running most DevOps tools:
| Tool | Command |
|---|---|
| Git | sudo apt install git |
| Docker | sudo apt install docker.io |
| Kubernetes CLI | curl -LO https://dl.k8s.io/release/... && chmod +x kubectl |
| Terraform | wget https://... && unzip terraform.zip |
These tools become part of your toolchain and are often automated via scripts during infrastructure setup.
๐ง Conclusion
Linux commands are the foundation of every DevOps professionalโs toolkit. Whether youโre automating deployments, debugging servers, or managing cloud instances, a strong command-line fluency helps you move faster and work smarter.
๐ Practice daily, incorporate them into your scripts, and consider creating aliases or functions for repetitive tasks.
If you found this post helpful:
- โ Subscribe to my YouTube Channel for tutorials on AWS, Linux, and DevOps.
- ๐ฌ Comment below your favorite Linux command or share one that helped you in production.
- ๐ Follow me on LinkedIn for more tips and updates.
