Linux is the backbone of DevOps. Mastering advanced Linux commands can significantly boost your productivity and troubleshooting skills. This guide covers essential system monitoring, networking, security, automation, and DevOps-specific commands.
π Table of Contents
- System and Resource Monitoring
- Networking and Connectivity
- Process and Job Management
- Security and User Management
- Disk Management and File Operations
- DevOps-Specific Commands
- Automation and Scheduling
βοΈ 1. System and Resource Monitoring
Monitor system performance and resource usage with these commands:
htop
- A more interactive version of
top
, displaying system resource usage in real-time.
vmstat 1 5
- Displays CPU, memory, and I/O statistics every second for five iterations.
iostat -c 2 5
- Monitors CPU usage every two seconds, repeated five times.
sar -u 5 5
- Collects and reports CPU usage statistics every five seconds.
mpstat -P ALL 5
- Displays per-core CPU usage every five seconds.
π 2. Networking and Connectivity
Diagnose and debug network issues efficiently:
ss -tulnp
- Lists open ports and listening services.
ip route show
- Displays the system's routing table.
nmap -sP 192.168.1.0/24
- Scans the local network for active devices.
tcpdump -i eth0 port 80
- Captures network packets on the
eth0
interface for HTTP traffic analysis.
dig example.com +short
- Performs a DNS lookup to resolve domain names.
nc -zv google.com 443
- Checks if a remote server's port is open.
π 3. Process and Job Management
Manage running processes and background jobs:
jobs -l
- Lists all background jobs.
fg %1
- Brings job number
1
to the foreground.
bg %1
- Resumes job
1
in the background.
pkill -f "process_name"
- Kills a process by name.
nohup command &
- Runs a command even after logging out.
π 4. Security and User Management
Enhance system security with these commands:
sudo visudo
- Edits the sudoers file securely.
usermod -aG docker username
- Adds a user to the
docker
group.
passwd -l username
- Locks a user account.
find / -perm /4000 2>/dev/null
- Finds files with the SUID bit set (potential security risks).
history | awk '{print $2}' | sort | uniq -c | sort -nr | head -10
- Displays the top 10 most used commands.
πΎ 5. Disk Management and File Operations
Efficiently manage disk space and files:
lsblk
- Lists storage devices and partitions.
mount | column -t
- Displays mounted filesystems in a readable format.
du -ah /var/log | sort -rh | head -10
- Shows the top 10 largest log files.
rsync -avzh source/ destination/
- Syncs files between directories or servers efficiently.
tar -czvf backup.tar.gz /path/to/backup
- Compresses a directory into a
.tar.gz
file.
π 6. DevOps-Specific Commands
Essential commands for CI/CD, Docker, Kubernetes, and Terraform:
docker ps -a
- Lists all running and stopped Docker containers.
docker images
- Displays locally stored Docker images.
kubectl get pods --all-namespaces
- Lists all Kubernetes pods across namespaces.
kubectl logs -f pod-name
- Streams logs from a Kubernetes pod.
terraform fmt && terraform validate
- Formats and validates Terraform configuration.
ansible-playbook -i inventory playbook.yml --check
- Runs an Ansible playbook in dry-run mode.
git log --oneline --graph --all
- Displays a graphical representation of Git commit history.
π€ 7. Automation and Scheduling
Automate tasks and schedule jobs:
watch -n 5 df -h
- Runs
df -h
every five seconds.
alias ll='ls -lah'
- Creates a shortcut for
ls -lah
.
crontab -l
- Lists scheduled cron jobs.
at 10:30 PM tomorrow
- Schedules a command to run at a specific time.
π₯ Final Thoughts
Mastering these advanced Linux commands will elevate your DevOps skills, helping you debug issues, automate workflows, and optimize performance.
π¬ Which Linux command do you find most useful in your DevOps journey? Letβs discuss in the comments! π
Top comments (0)