Linux Shell DevOps

Essential Linux Commands for DevOps Engineers

AK
Alex Kumar
Linux Systems Engineer
Jan 05, 2025
20 min read

What You'll Learn

This guide covers 60+ essential Linux commands that every DevOps, cloud, and backend engineer must master — from basic navigation to process management, text processing, and networking.

1. Navigation & File Operations

These are the bread-and-butter commands you'll use every single day in a Linux environment.

bash
# Navigation
ls -la                    # List all files (including hidden) with details
ls -lh                    # Human-readable file sizes
cd /var/log               # Change directory
cd ~                      # Go to home directory
cd -                      # Go to previous directory
pwd                       # Print working directory

# File operations
cp -r source/ dest/       # Copy directory recursively
mv oldname newname        # Move or rename file/directory
rm -rf directory/         # Remove directory recursively (CAUTION!)
mkdir -p path/to/dir      # Create nested directories
touch newfile.txt         # Create empty file or update timestamp

# View files
cat /etc/hosts            # Print file contents
less /var/log/syslog      # View file with scrolling (q to quit)
head -n 20 file.log       # First 20 lines
tail -n 50 file.log       # Last 50 lines
tail -f /var/log/nginx/access.log  # Follow log in real-time (VERY useful!)

2. Text Search & Processing (The Power Tools)

These commands are what separate Linux novices from power users. grep, awk, and sed can transform how you work with data.

bash
# grep — Search text patterns
grep "error" /var/log/syslog              # Find lines with "error"
grep -i "error" file.log                  # Case-insensitive
grep -r "TODO" /var/www/html/             # Recursive search
grep -n "WARN" app.log                    # Show line numbers
grep -v "DEBUG" app.log                   # Show lines WITHOUT DEBUG
grep -E "ERROR|FATAL" app.log             # Extended regex (OR)
grep -c "404" access.log                  # Count matching lines

# awk — Column-based text processing
awk '{print $1, $4}' access.log           # Print columns 1 and 4
awk -F: '{print $1}' /etc/passwd         # Use ":" as delimiter, print field 1
awk '$3 > 100 {print $0}' data.txt       # Print rows where column 3 > 100
awk 'NR==5,NR==10' file.txt              # Print lines 5 to 10

# sed — Stream editor (find & replace)
sed 's/old/new/g' file.txt               # Replace "old" with "new" globally
sed -i 's/old/new/g' file.txt            # In-place replacement (modifies file!)
sed -i 's/localhost/192.168.1.1/g' config.conf  # Replace in config
sed '/^#/d' config.txt                   # Delete comment lines (starting with #)
sed -n '10,20p' file.txt                 # Print only lines 10-20

# find — Search for files
find / -name "*.log" -type f             # Find all .log files
find /var -name "*.log" -mtime -7        # Modified in last 7 days
find . -size +100M                       # Files larger than 100MB
find . -perm 777                         # Files with 777 permissions
find . -user nginx -type f               # Files owned by nginx
find . -name "*.conf" -exec grep -l "ssl" {} \;  # Find conf files containing "ssl"

3. File Permissions & Ownership

Understanding permissions is critical for security. Every file in Linux has owner, group, and other permission bits.

chmod — Change Permissions

chmod 755 script.sh    # rwxr-xr-x
chmod 644 file.conf    # rw-r--r--
chmod +x deploy.sh     # Add execute bit
chmod -R 755 /var/www/ # Recursive

# Numeric: r=4, w=2, x=1
# 7 = rwx (owner)
# 5 = r-x (group, others)
# 4 = r-- (read only)

chown — Change Owner

chown nginx:nginx /var/www/html
chown -R www-data:www-data /app/
chown root /etc/cron.d/backup
chgrp docker /usr/bin/docker

# View current ownership
ls -la /etc/nginx/nginx.conf
stat /etc/passwd

4. Process Management

Monitor and control running processes — essential for diagnosing performance issues and managing system resources.

bash
# Process listing
ps aux                             # All running processes
ps aux | grep nginx                # Find nginx process
ps aux --sort=-%mem | head -10     # Top 10 memory consumers
ps -ef --forest                    # Process tree

# top / htop — Interactive process monitoring
top                                # Live process view
htop                               # Better UI (may need to install)
top -u www-data                    # Processes by user

# kill — Terminate processes
kill 1234                          # Send SIGTERM (graceful)
kill -9 1234                       # Send SIGKILL (force kill)
killall nginx                      # Kill all nginx processes
pkill -f "python app.py"           # Kill by pattern

# Background jobs
./long_script.sh &                 # Run in background
jobs                               # List background jobs
fg 1                               # Bring job 1 to foreground
nohup ./script.sh > output.log &   # Run after logout (disown)
disown -h %1                       # Disown job 1

5. Networking Commands

bash
# Connectivity testing
ping -c 4 google.com               # Send 4 ICMP packets
traceroute google.com              # Trace network path
tracepath google.com               # Alternative (no root needed)

# SSH — Remote access
ssh user@192.168.1.10              # Connect to remote host
ssh -i ~/.ssh/my-key.pem ec2-user@18.x.x.x  # AWS EC2 connect
ssh -L 8080:localhost:80 user@server  # Port forwarding (local)
ssh -R 9090:localhost:3000 user@server  # Reverse tunnel

# File transfer
scp file.txt user@server:/home/user/     # Copy to remote
scp -r /local/dir user@server:/remote/  # Copy directory
rsync -avz ./app/ user@server:/var/www/  # Sync with progress

# Network info
ip addr show                       # Interface IP addresses
ip route show                      # Routing table
ss -tulnp                          # Open ports and listeners
netstat -tulnp                     # (older alternative)
curl -I https://example.com        # HTTP headers check
wget -q -O /dev/null https://url   # Test download speed
nslookup example.com               # DNS lookup
dig example.com A                  # Detailed DNS query

6. Disk & Storage Management

bash
df -h                              # Disk space (human-readable)
df -i                              # Inode usage (important!)
du -sh /var/log/                   # Directory size summary
du -sh /* 2>/dev/null | sort -rh | head -10  # Largest dirs

lsblk                              # List block devices
fdisk -l                           # Partition table (root needed)
mount | grep "^/dev"               # Currently mounted devices
free -h                            # RAM and swap usage
vmstat 1 5                         # System stats (1s interval, 5 times)

7. System Info & Logs

bash
uname -a                           # Kernel and OS info
cat /etc/os-release                # Distribution details
uptime                             # System uptime and load average
w                                  # Who is logged in
last                               # Login history
dmesg | tail -50                   # Kernel ring buffer

# Journald (systemd logs)
journalctl -xe                     # Recent logs with context
journalctl -u nginx --since "1 hour ago"  # Nginx logs, last hour
journalctl -f                      # Follow system log (like tail -f)
journalctl --disk-usage            # Log disk usage

# systemctl — Service management
systemctl status nginx             # Service status
systemctl start/stop/restart nginx # Start/stop/restart
systemctl enable nginx             # Auto-start on boot
systemctl disable nginx            # Remove auto-start
systemctl list-units --type=service  # All services

Pro Tips

  • Ctrl+R — Reverse search your command history. Type any part of a previous command.
  • !! — Re-run the last command. sudo !! re-runs the last command with sudo.
  • Ctrl+A / Ctrl+E — Jump to start/end of the line.
  • watch -n 2 "df -h" — Run any command every 2 seconds (great for monitoring).
  • history | awk '{print $2}' | sort | uniq -c | sort -rn | head — Your most-used commands.

Keep Reading

D
DevOps

Docker Networking Demystified: Bridge, Host & Overlay

8 min read Read More
C
Cloud

AWS IAM Roles vs Users vs Policies

10 min read Read More
P
Programming

Understanding Python's GIL & Multiprocessing

14 min read Read More