Linux Terminal

The Terminal is Your Superpower

Every DevOps engineer lives in the terminal. Master these commands and you'll work 10x faster than GUI-dependent colleagues.

File Navigation & Management

# Navigate like a pro
cd -                    # Go to previous directory
cd ~                    # Home directory
pwd                     # Where am I?

# List files with style
ls -la                  # All files, long format
ls -lah                 # Human-readable sizes
ls -lt                  # Sort by time
tree -L 2               # Directory tree, 2 levels

# Find files
find . -name "*.log"    # Find by name
find . -size +100M      # Find large files
find . -mtime -7        # Modified in last 7 days

Text Processing Powerhouse

grep - Search Like a Ninja

# Basic search
grep "error" app.log

# Case insensitive, recursive
grep -ri "password" /etc/

# Show line numbers and context
grep -n -A 3 -B 3 "Exception" app.log

# Invert match (exclude)
grep -v "DEBUG" app.log

awk - Data Extraction

# Print specific columns
awk '{print $1, $3}' access.log

# Sum numbers in column
awk '{sum += $5} END {print sum}' data.txt

# Filter by condition
awk '$3 > 500 {print $1}' access.log

sed - Stream Editor

# Replace text
sed 's/old/new/g' file.txt

# Delete lines
sed '/pattern/d' file.txt

# In-place edit
sed -i 's/foo/bar/g' config.cfg

Process Management

# View processes
ps aux | grep nginx
top                     # Interactive process viewer
htop                    # Better top (install it!)

# Kill processes
kill -9 PID             # Force kill
killall nginx           # Kill by name
pkill -f "python app"   # Kill by pattern

# Background jobs
./script.sh &           # Run in background
nohup ./script.sh &     # Survive logout
jobs                    # List background jobs
fg %1                   # Bring job to foreground

Disk & Network

# Disk usage
df -h                   # Filesystem usage
du -sh *                # Directory sizes
du -sh * | sort -h      # Sorted by size

# Network
netstat -tlnp           # Open ports
ss -tlnp                # Modern netstat
curl -I https://site.com  # HTTP headers
wget -O file.zip URL    # Download file

Shell Scripting Basics

Variables & Conditionals

#!/bin/bash

# Variables
NAME="DevOps"
COUNT=42

# Conditionals
if [ "$COUNT" -gt 40 ]; then
    echo "High count!"
elif [ "$COUNT" -eq 40 ]; then
    echo "Exactly 40"
else
    echo "Low count"
fi

# File checks
if [ -f "/path/to/file" ]; then
    echo "File exists"
fi

Loops

# For loop
for server in web1 web2 web3; do
    ssh $server "uptime"
done

# While loop
while read -r line; do
    echo "Processing: $line"
done < servers.txt

# Counter loop
for i in {1..10}; do
    echo "Iteration $i"
done

Functions

deploy() {
    local env=$1
    echo "Deploying to $env..."
    # deployment logic here
    return 0
}

# Call the function
deploy "production"

Pro One-Liners

# Count lines of code
find . -name "*.py" | xargs wc -l

# Watch log file
tail -f /var/log/syslog | grep --line-buffered "error"

# Disk hogs
du -sh * 2>/dev/null | sort -rh | head -10

# Memory usage by process
ps aux --sort=-%mem | head -10

# Parallel execution
cat servers.txt | xargs -P 4 -I {} ssh {} "hostname"

# Quick HTTP server
python3 -m http.server 8080

# Generate random password
openssl rand -base64 32

Essential Tools to Install

sudo apt install -y \
    htop \
    ncdu \
    jq \
    tmux \
    vim \
    git \
    curl \
    wget \
    tree

The terminal is where DevOps magic happens. Practice daily, and these commands will become second nature! 🐧