Linux Fundamentals for DevOps Engineers
Master the operating system that powers the cloud. This guide covers the essential Linux concepts and commands you need to succeed in DevOps.
Why is Linux Essential in DevOps?
Linux is the bedrock of modern cloud computing and DevOps. Over 90% of public cloud instances run on Linux. Its open-source nature, stability, and powerful command-line interface (CLI) make it the ideal environment for automating, deploying, and managing applications at scale. For a DevOps engineer, fluency in Linux isn't just a skill—it's a necessity.
Core Linux Concepts
File System Structure
The Linux file system is a hierarchical tree structure.
Everything starts from the root directory, represented by a
forward slash (/). Key directories include:
/bin: Essential user command binaries./etc: System configuration files./home: User home directories./var/log: System log files./tmp: Temporary files.
File Permissions
Permissions control who can read, write, or execute a file.
They are assigned to three categories: the owner (user), the
group, and others. Permissions are represented by characters
(rwx) or numbers (e.g., 755).
Processes and Services
A process is any program in execution. A
service (or daemon) is a process that runs in
the background. Modern Linux systems use
systemd to manage services, allowing you to start,
stop, and enable them to run on boot.
Networking
Understanding basic networking is crucial. This includes knowing how to check IP addresses, test connectivity, view open ports, and troubleshoot network issues using command-line tools.
Logs
Logs are your first stop for troubleshooting. System and
application logs, typically found in /var/log,
provide a detailed record of events, errors, and warnings.
Linux Architecture Diagram
Simplified Linux Architecture
Hardware → Kernel → Shell (CLI) → User Space (Applications)
The Kernel is the core of the OS, managing hardware. The Shell is the command-line interface you use to interact with the Kernel. User Space is where your applications run.
Essential Command Cheat Sheet
| Command | Description | Example |
|---|---|---|
ls -la |
List all files (including hidden) with details. | ls -la /home/user |
cd |
Change directory. | cd /var/log |
pwd |
Print the current working directory. | pwd |
ps aux |
List all running processes. | ps aux | grep nginx |
top |
Display real-time process information. | top |
grep |
Search for a pattern in text. | grep "error" app.log |
chmod |
Change file permissions. | chmod 755 script.sh |
chown |
Change file owner and group. | chown www-data:www-data /var/www |
systemctl |
Manage systemd services. | systemctl status nginx |
journalctl |
Query the systemd journal (logs). | journalctl -u nginx -f |
df -h |
Display disk space usage in human-readable format. | df -h |
free -h |
Display memory usage in human-readable format. | free -h |
ip addr |
Show IP addresses and network interfaces. | ip addr |
netstat -tuln |
List all listening TCP and UDP ports. | netstat -tuln |
Real-World Troubleshooting Examples
1. Web Server is Down
-
Check the service status:
systemctl status nginx -
Check the logs for errors:
journalctl -u nginx | tail -n 50 -
Check if it's listening on port 80:
netstat -tuln | grep :80
2. Application is Slow
-
Check CPU/Memory usage: Use
toporhtopto see which processes are consuming the most resources. -
Check disk I/O: Use
iostatto see if the disk is a bottleneck. -
Check for memory leaks: Monitor memory usage
over time with
free -h.
Interview Questions for DevOps Engineers
-
How would you find all files in the
/etcdirectory that were modified in the last 7 days?Answer:
find /etc -mtime -7 -
Explain the difference between a hard link and a symbolic link.
Answer: A hard link is a direct reference to the file's inode, while a symbolic (or soft) link is a pointer to the file's path. Deleting the original file breaks a symbolic link but not a hard link (until all hard links are removed).
-
A service is failing to start. What are the first three commands you would run to diagnose the problem?
Answer: 1.
systemctl status <service-name>to get a high-level status. 2.journalctl -u <service-name>to check the detailed logs. 3./path/to/binary --config-test(e.g.,nginx -t) to validate the configuration file.