🚀 Essential Bash Commands for DevOps Engineers

Categorized with Description

1. File & Directory Management

ls -la
List files/directories with hidden files and details
Example: ls -la /etc/
pwd
Print Working Directory
Example: pwd
cd
Change Directory
Example: cd /var/log
mkdir -p
Create directories recursively
Example: mkdir -p /app/logs/{error,info}
rm -rf
Remove files/directories forcefully (use with caution)
Example: rm -rf /tmp/cache/*
cp -r
Copy recursively
Example: cp -r /app/config /backup/
mv
Move or rename
Example: mv old.log new.log
find
Search files/directories
Example: find /var/log -name "*.log" -mtime -1
df -h
Disk usage in human readable format
Example: df -h
du -sh
Directory size summary
Example: du -sh /var/log/*

2. System Information & Monitoring

top / htop
Interactive process viewer (htop is better)
Example: htop
ps aux
List all running processes
Example: ps aux | grep nginx
free -h
Memory usage in human readable
Example: free -h
uptime
System uptime and load average
Example: uptime
uname -a
Kernel and system information
Example: uname -a
lscpu
CPU architecture information
Example: lscpu
vmstat 1 5
Virtual memory statistics
Example: vmstat 1 10
iostat -x 1
CPU and disk I/O statistics
Example: iostat -x 1 5

3. Process Management

kill -9 PID
Force kill process
Example: kill -9 12345
pkill -f name
Kill process by name
Example: pkill -f nginx
nohup
Run command immune to hangup
Example: nohup ./app &
jobs / fg / bg
Job control
Example: jobs
nice -n 10
Run with lower priority
Example: nice -n 15 backup.sh

4. Text Processing & Search

grep -E
Search with regex
Example: grep -E "error|fail" app.log
awk
Powerful text processing
Example: awk '{print $1, $NF}' access.log
sed 's/old/new/g'
Stream editor (find & replace)
Example: sed -i 's/localhost/127.0.0.1/g' config.yaml
cut -d: -f1
Cut fields from lines
Example: cut -d: -f1 /etc/passwd
sort -nr
Sort numerically reverse
Example: du -sh * | sort -nr
uniq -c
Count unique lines
Example: cat access.log | cut -d' ' -f1 | sort | uniq -c | sort -nr
wc -l
Word/Line count
Example: wc -l *.log

5. Networking & Connectivity

curl -I
HTTP headers only
Example: curl -I https://example.com
wget
Download files
Example: wget https://example.com/file.tar.gz
ping -c 4
Check connectivity
Example: ping -c 4 google.com
netstat -tuln
Network connections (or ss command)
Example: ss -tuln
dig / nslookup
DNS lookup
Example: dig example.com
ssh -i key.pem user@host
SSH with key
Example: ssh -i ~/.ssh/id_rsa user@192.168.1.100
scp
Secure copy
Example: scp app.tar.gz user@server:/opt/
rsync -avz
Sync files efficiently
Example: rsync -avz /src/ user@server:/dest/

6. Package Management

apt update && apt upgrade
Update packages (Debian/Ubuntu)
Example: sudo apt update && sudo apt upgrade -y
yum update
Update packages (CentOS/RHEL)
Example: sudo yum update -y
dnf
Modern yum replacement
Example: sudo dnf install nginx

7. Git Commands

git status
Show working tree status
Example: git status
git log --oneline --graph
Pretty commit history
Example: git log --oneline --graph --all
git fetch --all --prune
Update remote branches
Example: git fetch --all --prune

8. Docker & Container Commands

docker ps -a
List all containers
Example: docker ps -a
docker logs -f
Follow container logs
Example: docker logs -f nginx
docker exec -it
Enter running container
Example: docker exec -it mysql bash
kubectl get pods
List Kubernetes pods
Example: kubectl get pods -n production
kubectl logs -f
Follow pod logs
Example: kubectl logs -f deployment/app

9. Permissions & Security

chmod +x
Make script executable
Example: chmod +x deploy.sh
chown -R
Change ownership recursively
Example: chown -R www-data:www-data /var/www
sudo !!
Repeat last command with sudo
Example: sudo !!
ssh-keygen
Generate SSH keys
Example: ssh-keygen -t ed25519

10. Archives & Compression

tar -czvf
Create gzip tarball
Example: tar -czvf backup.tar.gz /app/
tar -xzvf
Extract tarball
Example: tar -xzvf backup.tar.gz
zip -r
Create zip archive
Example: zip -r archive.zip folder/

11. Miscellaneous & Scripting

watch -n 1
Run command periodically
Example: watch -n 1 "df -h"
alias
Create shortcuts
Example: alias ll='ls -la'
export
Set environment variable
Example: export ENV=production
source / .
Load script in current shell
Example: source ~/.bashrc
jq '.'
JSON processor
Example: curl api | jq '.users[] | .name'
timeout 10s
Limit command execution time
Example: timeout 5s ping google.com