Mastering Linux for DevOps: Commands and Concepts Every Engineer Must Know

Table of contents

Introduction
Linux is the heart of DevOps. It runs most servers, containers, and automation scripts, making it an essential skill for DevOps engineers. This guide offers a comprehensive yet practical approach to mastering Linux for DevOps roles. We’ll cover everything from basics to advanced system management, scripting, and real-world command use.
Why Linux Matters in DevOps
DevOps aims to bridge the gap between development and operations. Since most cloud environments and servers are Linux-based, understanding Linux enables DevOps engineers to:
Automate infrastructure tasks using shell scripting
Monitor and manage system performance
Deploy and troubleshoot applications in production
Build and manage CI/CD pipelines
Handle containerized environments like Docker and Kubernetes
Part 1: Linux Basics
1.1. Understanding the Linux Filesystem Structure
The Linux filesystem is organized in a hierarchical tree structure, starting from the root directory /
. Each directory has a specific role and purpose in the system. As a DevOps engineer, understanding these directories helps you locate configuration files, manage services, and troubleshoot issues efficiently.
Here are some key directories:
/
– The root of the filesystem. Every file and directory starts here./bin
– Essential command-line binaries (likels
,cp
,mv
) needed for basic system operations./etc
– Configuration files for the system and installed services./var
– Variable data like logs (/var/log/
), mail, and temporary files./usr
– User-installed software and libraries; contains subdirectories like/usr/bin
and/usr/lib
./home
– Home directories for regular users (e.g.,/home/devuser
)./tmp
– Temporary files; cleared on reboot./dev
– Device files for hardware components./proc
– Virtual filesystem for process and system information (e.g., CPU, memory usage)./opt
– Optional third-party application packages.
1.2. Navigation Commands
Navigating the Linux filesystem is a core skill. These commands help you move through directories, understand where you are, and manage your working environment efficiently.
pwd # Print the current working directory
cd /path # Change directory to specified path
cd .. # Move up one directory level
cd ~ # Move to the current user's home directory
cd - # Switch to the previous working directory
ls # List files and directories in the current location
ls -l # Long listing format with permissions, size, owner, etc.
ls -a # Show all files including hidden ones (starting with .)
clear # Clear the terminal screen
1.3. File and Directory Management
Managing files and directories efficiently is essential for maintaining your Linux environment. These commands help you create, move, copy, rename, and delete files and folders quickly.
touch file.txt # Create file
mkdir folder # Create directory
cp source.txt dest.txt # Copy file
mv file.txt /tmp/ # Move or rename
rm file.txt # Remove file
rm -rf folder/ # Force delete folder
🛑 Caution: Use rm -rf
carefully (it deletes recursively and forcefully, which can cause data loss if misused)
Part 2: User and Permission Management
2.1. User Management
Managing users is a key responsibility for system administrators and DevOps engineers. These commands allow you to add, modify, and manage users and their access on a Linux system.
whoami # Show the current logged-in username
id <username> # Display user ID (UID), group ID (GID), and group membership
adduser <username> # Add a new user (with home directory)
useradd <username> # Add a user (less interactive than adduser)
passwd <username> # Set or change user password
usermod -aG <group> <user> # Add a user to a group (e.g., sudo)
deluser <username> # Delete a user and optionally their home directory
userdel -r <username> # Delete a user and their home directory
2.2. Permissions
Linux uses a permission-based model to control access to files and directories. Understanding and managing these permissions is critical for system security and proper resource usage.
View Permissions
ls -l # Show permissions, ownership, size, and timestamp
Change Permissions
r
= read,w
= write,x
= executeFirst set: user, second: group, third: others
chmod 755 <file> # Set read/write/execute for owner, read/execute for group and others
chmod u+x <file> # Add execute to owner only
chmod -R 644 <dir> # Recursively set read/write for owner, read-only for group and others
Change Ownership
chown user <file> # Change ownership to a new user
chown user:group <file> # Change owner and group
chown -R user:group <dir> # Recursively change ownership
Avoid setting 777
permissions—it gives full access to everyone and is a major security risk.
Part 3: Process Management
Processes are running instances of programs. As a DevOps engineer, monitoring and managing them is key to maintaining system stability and diagnosing issues quickly.
3.1 View Running Processes
ps # Show processes running in the current shell
ps aux # List all running processes with full details
top # Live view of system resource usage (CPU, memory)
htop # Interactive version of `top` (install separately)
3.2 Filter or Search Processes
ps aux | grep <name> # Find processes by name
pgrep <name> # Get process IDs by name
3.3 Kill or Control Processes
kill <PID> # Send TERM signal to stop a process
kill -9 <PID> # Force kill (SIGKILL) a process
pkill <name> # Kill process by name
killall <name> # Kill all processes with the given name
3.4 Manage Background & Foreground Jobs
command & # Run a command in the background
jobs # List background jobs in current shell
fg %1 # Bring job 1 to the foreground
bg %1 # Resume job 1 in background
Part 4: Resource Monitoring
Resource monitoring is essential for performance tuning, troubleshooting, and ensuring service availability. Here are key commands to monitor CPU, memory, disk, and network usage:
4.1 CPU & Memory
top # Live view of CPU and memory usage
htop # Advanced interactive viewer (requires install)
vmstat 1 # System performance stats (CPU, memory, processes)
free -h # Show memory usage in human-readable format
uptime # System uptime and average load
4.2 Disk Usage
df -h # Disk space usage (human-readable)
du -sh <dir> # Size of a directory
du -ah | sort -rh | head -n 10 # Top 10 largest files/folders
4.3 Network Usage
ip a # Show IP addresses
ss -tuln # List listening ports and open sockets
netstat -tuln # (Older systems) Show open ports
iftop # Real-time network traffic monitor (install required)
4.4 File System I/O
iostat # CPU and disk I/O stats (install via sysstat)
iotop # Real-time disk read/write by process (requires root)
Part 5: Package Management
Linux package managers help you install, update, and remove software—crucial for setting up environments, CI/CD tools, and automation scripts. Different distros use different managers, so here are the most common ones:
5.1 For Debian/Ubuntu (APT)
sudo apt update # Refresh package index
sudo apt upgrade # Upgrade installed packages
sudo apt install <pkg> # Install a package
sudo apt remove <pkg> # Remove a package
sudo apt purge <pkg> # Remove a package + config files
sudo apt autoremove # Remove unused dependencies
dpkg -l # List installed packages
5.2 For RHEL/CentOS/Fedora (YUM/DNF)
sudo yum update # Update all packages (YUM)
sudo dnf update # Update all packages (DNF - newer)
sudo yum install <pkg> # Install a package
sudo yum remove <pkg> # Remove a package
rpm -qa # List installed packages (RPM)
5.3 Some more Useful Queries
which <cmd> # Show the path of a command
whereis <cmd> # Show all locations of a command
apt list --installed # List all installed packages (APT)
Part 6 : Disk and Filesystem Management
Efficient disk and filesystem management is vital for performance, backups, and troubleshooting in any DevOps environment. These commands help you monitor, manage, and optimize storage.
6.1 Disk Usage and Space
df -h # Show mounted filesystems and their disk usage
du -sh <dir> # Get total size of a directory
du -ah | sort -rh # List and sort all files by size (descending)
lsblk # List block devices (disks and partitions)
6.2 Mounting and Unmounting Filesystems
mount /dev/sdX1 /mnt # Mount a device to a directory
umount /mnt # Unmount the filesystem
mount -a # Mount all filesystems in /etc/fstab
Note: You may need to create the mount point directory first using mkdir /mnt
.
6.3 Filesystem Types and Checks
df -T # Show filesystem types
blkid # View UUID and filesystem type of devices
file -s /dev/sdX # Check filesystem on a block device
6.4 Disk Health and Cleanup
fsck /dev/sdX1 # Check and repair a filesystem
tune2fs -l /dev/sdX1 # View/ext2/ext3/ext4 filesystem parameters
sync # Flush filesystem buffers
Tip: Automate disk usage checks with cron jobs or system monitoring tools like Glances
, Netdata
, or Zabbix
.
Part 7: Log Management
Logs are the first place to check when something breaks. Whether it's system failures, application crashes, or performance bottlenecks—effective log handling is essential for every DevOps engineer.
7.1 Where Logs Live (Linux)
Most Linux system and service logs are stored in:
/var/log/
🔹 Common log files:
/var/log/syslog
– General system logs (Ubuntu)/var/log/messages
– System messages (RHEL/CentOS)/var/log/auth.log
– Authentication events (login, sudo)/var/log/dmesg
– Kernel ring buffer/var/log/nginx/
– NGINX logs/var/log/httpd/
– Apache logs
7.2 Commands to Read Logs
cat /var/log/syslog # Print full log
less /var/log/syslog # Scrollable log viewer
tail -n 100 /var/log/syslog # View last 100 lines
tail -f /var/log/syslog # Live-updating logs
grep "error" /var/log/syslog # Filter for "error"
7.3 Logs in Containers and Kubernetes
Docker:
docker logs <container_name> # View logs of a container
docker logs -f <container_name> # Live log stream
Kubernetes:
kubectl logs <pod-name> # Logs for a pod
kubectl logs -f <pod-name> # Stream logs
kubectl logs <pod> -c <container> # Specific container in pod
Part 8: Shell Scripting Basics for Automation
Automation is the core of DevOps. Shell scripting helps automate repetitive tasks like deployments, backups, monitoring, and system configuration.
8.1 Why Shell Scripting Matters in DevOps
Automate server setup (e.g., install packages, create users)
Schedule cron jobs for backups/log rotation
Write CI/CD pre/post hooks
Create simple monitoring tools
Automate log analysis
8.2 Basic Script Structure
#!/bin/bash
echo "Hello, DevOps World!"
#!/bin/bash
– shebang: tells the system to use Bash shellSave the script as
myfirstscript.sh
, make it executable:
chmod +x myscript.sh
./myfirstscript.sh
8.3 Common Commands Used in Scripts
echo, read # Output and input
if, elif, else # Conditional logic
for, while, until # Loops
case # Pattern matching
functions # Code reuse
Conclusion
Linux is the backbone of modern DevOps practices, and mastering its essentials is non-negotiable for any aspiring engineer. From understanding the filesystem to managing users, permissions, packages, and logs every concept and command builds our confidence in handling real-world infrastructure.
By learning basic shell scripting, we’ve taken the first big step toward automation—one of the core pillars of DevOps. These scripts will empower us to automate routine tasks, boost productivity, and minimize human error.
In the next part of this series, we'll explore cron jobs and task scheduling, equipping with the tools to automate these scripts on a schedule taking our DevOps skills to the next level.
Stay tuned, and keep scripting our way to DevOps mastery.
Subscribe to my newsletter
Read articles from Himanth Akula directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Himanth Akula
Himanth Akula
Hi to the fellow tech enthusiasts out there! 👋 I'm an aspiring Cloud and DevOps Engineer ☁️ 🚀 Passionate about creating resilient, secure, and cost-effective infrastructure on AWS. 🐳 Proficient in containerization with Docker and Kubernetes. 🔄 Building expertise in CI/CD pipelines using Jenkins, GitHub Actions, AWS CodePipeline, and more. 📜 Exploring Infrastructure as Code (IaC) with Terraform and configuration management with Ansible. 🌟 Dedicated to continuous learning and sharing knowledge to grow together with the tech community. Let's connect and innovate! 🤝