🐧 DevOps Day 6 — Linux Fundamentals and Shell Scripting Basics
🚀 Introduction
As a DevOps engineer, mastering Linux and shell scripting helps you:
-
Automate manual tasks
-
Manage servers efficiently
-
Understand logs, permissions, and system resources
-
Integrate scripts into CI/CD pipelines
Today, we’ll explore Linux fundamentals, essential shell commands, and scripting basics that every DevOps professional should know.
🧩 What is Linux?
💡 Why Linux in DevOps?
-
Most cloud servers (AWS EC2, Azure VM, GCP Compute) use Linux distributions like Ubuntu, CentOS, or Amazon Linux.
-
Tools like Docker, Kubernetes, Ansible, and Jenkins run best on Linux.
-
You can easily automate infrastructure setup using shell scripts.
🧠 Common Linux Distributions
-
Ubuntu / Debian — popular for DevOps and CI/CD servers
-
CentOS / Red Hat (RHEL) — common in enterprise infrastructure
-
Amazon Linux 2 — AWS-optimized version for EC2
-
Alpine Linux — lightweight and used in Docker containers
⚙️ The Linux Architecture
Linux is made up of several layers working together:
-
Hardware — CPU, RAM, storage, network
-
Kernel — core of the system; manages hardware communication
-
Shell — interface for users to execute commands
-
User Space — applications and utilities
When you run a command like:
→ The shell interprets it → passes it to the kernel → retrieves data from the disk → displays the output.
💻 Navigating the Linux File System
📂 Basic Commands
| Task | Command | Description |
|---|---|---|
| Show current directory | pwd | Displays full path of current location |
| List files | ls | Lists files and folders |
| Detailed list | ls -l | Shows file permissions, owner, and size |
| Include hidden files | ls -a | Shows hidden files (those starting with .) |
| Change directory | cd /path | Move to a specific folder |
| Move up one level | cd .. | Goes one directory up |
| Go to home directory | cd ~ | Returns to your home folder |
💡 Tip: Combine commands with logical operators, for example:
This moves into /var/log and lists all files if the first command succeeds.
🧱 Working with Files and Directories
📄 Create, Move, Copy, Delete Files
📁 Directory Operations
💡 Be cautious with rm -rf — it permanently deletes files.
🖋️ Viewing and Editing Files
🧩 View File Contents
🧑💻 Create or Edit with VI Editor
Inside VI:
-
Press
i→ Insert mode -
Type your content
-
Press
Esc→ Type:wq→ Save and quit
💡 Shortcut: To quit without saving → :q!
📊 File Permissions and Ownership
Every file has permissions (read, write, execute) and an owner.
🔍 Check Permissions
Example output:
Meaning:
-
rwx (owner can read, write, execute)
-
r-x (group can read, execute)
-
r-- (others can read only)
🔧 Change Permissions
🧑 Change Owner
🧠 Resource Monitoring and Management
🧩 System Information
💾 Disk Usage
🧮 Memory and CPU
🕒 System Uptime
Displays how long the system has been running and load averages.
🧰 Shell Scripting Basics
Shell scripting is about automating repetitive tasks — deployment, backups, monitoring, or system setup.
Example:
Run Your Script:
💡 Tip:
-
Use variables to store reusable values
-
Use loops and conditionals for logic
-
Combine multiple Linux commands with pipes (
|) and redirection (>,>>)
🧭 Commonly Used Linux Shortcuts and Tricks
| Shortcut | Function |
|---|---|
Ctrl + C | Stop a running command |
Ctrl + L | Clear the terminal |
Ctrl + R | Search command history |
!! | Run the previous command |
history | Show command history |
alias ll='ls -alF' | Create a shortcut command |
⚙️ DevOps Use Cases for Linux
-
CI/CD Servers: Jenkins and GitLab runners run on Linux hosts
-
Containers: Docker containers use Linux namespaces and cgroups
-
Infrastructure: Ansible, Terraform, and Kubernetes rely on Linux command execution
-
Monitoring: Shell scripts automate log checks and alerts
🌟 Conclusion
“In DevOps, Linux isn’t a skill — it’s a language every engineer must speak fluently.”
Comments
Post a Comment