Linux Essentials for DevOps Engineers
· 3 min read
Linux is the backbone of modern infrastructure. Whether you're managing servers, containers, or cloud resources, Linux skills are essential.
File System Navigation
# Print working directory
pwd
# List files with details
ls -la
# Change directory
cd /var/log
# Create directories
mkdir -p /opt/myapp/{bin,config,logs}
# Find files
find /var -name "*.log" -mtime -7
# Search file contents
grep -r "error" /var/log/
File Operations
# Copy files
cp source.txt destination.txt
cp -r source_dir/ destination_dir/
# Move/rename files
mv oldname.txt newname.txt
# Remove files
rm -rf directory/ # Use with caution!
# View file contents
cat file.txt
less file.txt
head -n 20 file.txt
tail -f /var/log/syslog # Follow log in real-time
User and Permission Management
# View current user
whoami
# Switch user
sudo su - username
# Add user
sudo useradd -m -s /bin/bash newuser
# Change file permissions
chmod 755 script.sh
chmod u+x script.sh
# Change ownership
chown user:group file.txt
chown -R user:group directory/
# View permissions
ls -la
# drwxr-xr-x = directory, owner rwx, group rx, others rx
Process Management
# View running processes
ps aux
ps aux | grep nginx
# Real-time process monitor
top
htop
# Kill a process
kill -9 PID
pkill -f process_name
# Background processes
./long_running_script.sh &
nohup ./script.sh > output.log 2>&1 &
# View jobs
jobs
fg %1 # Bring to foreground
Networking
# Network interfaces
ip addr
ifconfig
# Test connectivity
ping google.com
traceroute google.com
# DNS lookup
nslookup google.com
dig google.com
# Active connections
netstat -tuln
ss -tuln
# Download files
curl -O https://example.com/file.tar.gz
wget https://example.com/file.tar.gz
# Transfer files
scp file.txt user@remote:/path/
rsync -avz source/ user@remote:/destination/
System Information
# System info
uname -a
hostnamectl
# Memory usage
free -h
# Disk usage
df -h
du -sh /var/log/*
# CPU info
lscpu
cat /proc/cpuinfo
Shell Scripting Basics
#!/bin/bash
# Simple deployment script
set -e # Exit on error
APP_NAME="myapp"
DEPLOY_DIR="/opt/$APP_NAME"
BACKUP_DIR="/opt/backups"
echo "Starting deployment..."
# Create backup
timestamp=$(date +%Y%m%d_%H%M%S)
tar -czf "$BACKUP_DIR/${APP_NAME}_${timestamp}.tar.gz" "$DEPLOY_DIR"
# Deploy new version
cd "$DEPLOY_DIR"
git pull origin main
npm install --production
pm2 restart $APP_NAME
echo "Deployment complete!"
Package Management
# Debian/Ubuntu (apt)
sudo apt update
sudo apt install nginx
sudo apt remove nginx
sudo apt autoremove
# RHEL/CentOS (yum/dnf)
sudo dnf update
sudo dnf install nginx
sudo dnf remove nginx
Essential Tools
| Tool | Purpose |
|---|---|
vim/nano | Text editors |
tmux/screen | Terminal multiplexer |
jq | JSON processor |
awk/sed | Text processing |
systemctl | Service management |
Master these fundamentals and you'll be ready for any DevOps challenge!
