50 Essential Linux Commands for DevOps Engineers: The Complete 2025 Cheat Sheet
Last updated: Aug 02, 2025 | Reading time: 12 minutes
Linux commands form the backbone of DevOps operations. Whether you’re managing servers, automating deployments, or troubleshooting production issues, mastering these essential Linux commands for DevOps will significantly boost your productivity and effectiveness as a DevOps engineer.
Table of Contents

File and Directory Operations
1. ls – List Directory Contents
# Basic listing
ls -la
# Sort by modification time
ls -lt
# Human-readable file sizes
ls -lh
# Show hidden files
ls -a
DevOps Use Case: Quickly inspect deployment directories and check file permissions during deployments.
2. cd – Change Directory
# Navigate to home directory
cd ~
# Go back to previous directory
cd -
# Navigate up two levels
cd ../../
3. pwd – Print Working Directory
pwd
DevOps Use Case: Verify current location when executing deployment scripts in different environments.
4. mkdir – Create Directories
# Create directory
mkdir /opt/myapp
# Create nested directories
mkdir -p /opt/myapp/{logs,config,data}
# Set permissions while creating
mkdir -m 755 /opt/secure-app
5. cp – Copy Files and Directories
# Copy file with backup
cp -b app.conf app.conf.backup
# Copy directory recursively
cp -r /source/dir /destination/dir
# Preserve timestamps and permissions
cp -p config.yml /etc/myapp/
6. mv – Move/Rename Files
# Rename file
mv old-config.yml new-config.yml
# Move with backup
mv -b app.log /var/log/
7. rm – Remove Files and Directories
# Remove file safely
rm -i important-file.txt
# Remove directory and contents
rm -rf /tmp/old-deployment
# Remove files older than 7 days
find /var/log -name "*.log" -mtime +7 -delete
8. find – Search Files and Directories
# Find files by name
find /opt -name "*.jar" -type f
# Find files modified in last 24 hours
find /var/log -mtime -1
# Find large files (>100MB)
find / -size +100M -type f
# Find and execute command
find /opt -name "*.log" -exec gzip {} \;
9. locate – Quick File Search
# Update database and search
updatedb && locate nginx.conf
10. which – Find Command Location
# Find executable path
which python3
which docker
You can manage files using tools like ls, cp, and rm. These are part of the GNU Core Utilities, essential for any Linux-based workflow.
If you’re looking for a focused list, check out our latest article on the Top 10 Linux Commands Every DevOps Engineer Must Master in 2025 — a curated list of must-know commands with real-world use cases.
Process Management
11. ps – Process Status
# Show all processes
ps aux
# Show process tree
ps auxf
# Show processes for specific user
ps -u nginx
# Show processes with specific command
ps aux | grep nginx
12. top – Real-time Process Monitor
# Standard top
top
# Show specific user processes
top -u username
# Show process threads
top -H
13. htop – Enhanced Process Viewer
# Interactive process viewer
htop
# Show tree view
htop -t
14. kill – Terminate Processes
# Graceful termination
kill -TERM 1234
# Force kill
kill -9 1234
# Kill by process name
killall nginx
# Kill processes by pattern
pkill -f "java.*myapp"
15. nohup – Run Commands in Background
# Run command that survives logout
nohup ./deploy.sh > deployment.log 2>&1 &
# Check background jobs
jobs
# Bring job to foreground
fg %1
16. systemctl – Service Management
# Start service
systemctl start nginx
# Enable service at boot
systemctl enable nginx
# Check service status
systemctl status nginx
# Reload service configuration
systemctl reload nginx
# Show all failed services
systemctl --failed
To monitor performance, top and htop give real-time system stats. For I/O and CPU stats, use iostat and vmstat.
System Monitoring and Performance
17. df – Disk Space Usage
# Show disk usage in human-readable format
df -h
# Show inode usage
df -i
# Show specific filesystem type
df -t ext4
18. du – Directory Space Usage
# Show directory sizes
du -h /var/log
# Show top-level directories only
du -h --max-depth=1 /opt
# Sort by size
du -h /var/log | sort -hr
19. free – Memory Usage
# Show memory in human-readable format
free -h
# Show memory every 2 seconds
free -s 2
# Show memory in MB
free -m
20. iostat – I/O Statistics
# Show I/O stats every 2 seconds
iostat -x 2
# Show CPU and I/O stats
iostat -c 1 5
21. sar – System Activity Reporter
# Show CPU usage for last 24 hours
sar -u
# Show memory usage
sar -r
# Show network statistics
sar -n DEV
22. vmstat – Virtual Memory Statistics
# Show system stats every 2 seconds
vmstat 2
# Show memory in MB
vmstat -S M
23. lscpu – CPU Information
# Show CPU details
lscpu
# Show CPU cache information
lscpu --cache
Network Operations
24. netstat – Network Statistics
# Show all listening ports
netstat -tuln
# Show established connections
netstat -tuna
# Show process using specific port
netstat -tulnp | grep :80
25. ss – Socket Statistics (modern netstat)
# Show listening TCP ports
ss -tln
# Show processes using sockets
ss -tlnp
# Show socket summary
ss -s
26. curl – Transfer Data from Servers
# Basic HTTP request
curl -I https://api.example.com/health
# POST request with JSON
curl -X POST -H "Content-Type: application/json" \
-d '{"key":"value"}' https://api.example.com/data
# Download file
curl -O https://releases.example.com/app-v1.2.tar.gz
# Follow redirects and show progress
curl -L --progress-bar -o file.zip https://example.com/file.zip
27. wget – Download Files
# Download file
wget https://example.com/file.tar.gz
# Download with custom user agent
wget --user-agent="DevOps-Bot/1.0" https://example.com/file
# Mirror website
wget --mirror --no-parent https://docs.example.com/
28. ping – Test Network Connectivity
# Ping with count
ping -c 4 google.com
# Ping with specific interval
ping -i 0.5 192.168.1.1
# Ping IPv6
ping6 google.com
29. traceroute – Trace Network Path
# Trace route to destination
traceroute google.com
# Use TCP instead of ICMP
traceroute -T google.com
30. dig – DNS Lookup
# Simple DNS lookup
dig google.com
# Query specific record type
dig google.com MX
# Reverse DNS lookup
dig -x 8.8.8.8
# Use specific DNS server
dig @8.8.8.8 google.com
Use netstat or ss to view open ports and connections. For checking DNS or HTTP endpoints, tools like dig, nslookup, and curl are indispensable.
Text Processing and Searching
31. grep – Search Text Patterns
# Search in files
grep -r "ERROR" /var/log/
# Case-insensitive search
grep -i "warning" application.log
# Show line numbers
grep -n "exception" error.log
# Exclude patterns
grep -v "DEBUG" application.log
# Show context around matches
grep -A 3 -B 3 "ERROR" application.log
32. awk – Text Processing
# Print specific columns
awk '{print $1, $3}' /var/log/access.log
# Sum values in column
awk '{sum+=$3} END {print sum}' data.txt
# Process CSV files
awk -F',' '{print $2}' data.csv
# Filter based on conditions
awk '$3 > 100 {print $0}' metrics.txt
33. sed – Stream Editor
# Replace text in file
sed 's/old-value/new-value/g' config.yml
# Delete lines containing pattern
sed '/DEBUG/d' application.log
# Insert line after match
sed '/\[database\]/a connection_timeout=30' config.ini
# In-place editing
sed -i 's/localhost/production-db/g' app-config.yml
34. sort – Sort Lines
# Sort file contents
sort /etc/passwd
# Numeric sort
sort -n numbers.txt
# Reverse sort
sort -r data.txt
# Sort by specific field
sort -k 3 -n data.txt
35. uniq – Remove Duplicate Lines
# Remove consecutive duplicates
uniq data.txt
# Count occurrences
uniq -c access.log
# Show only duplicates
uniq -d data.txt
36. wc – Word, Line, Character Count
# Count lines, words, characters
wc file.txt
# Count only lines
wc -l access.log
# Count files in directory
ls | wc -l
37. head – Show First Lines
# Show first 10 lines
head application.log
# Show first 20 lines
head -n 20 error.log
# Monitor file changes
head -f deployment.log
38. tail – Show Last Lines
# Show last 10 lines
tail error.log
# Follow file changes
tail -f application.log
# Show last 50 lines from multiple files
tail -n 50 /var/log/*.log
For log analysis and automation, tools like grep, awk, and sed help extract, process, and transform data efficiently.
Archive and Compression
39. tar – Archive Files
# Create archive
tar -czf backup-$(date +%Y%m%d).tar.gz /opt/myapp
# Extract archive
tar -xzf backup.tar.gz
# List archive contents
tar -tzf backup.tar.gz
# Create archive excluding files
tar --exclude='*.log' -czf app-backup.tar.gz /opt/myapp
40. gzip/gunzip – Compress Files
# Compress file
gzip large-log.txt
# Decompress file
gunzip large-log.txt.gz
# Keep original file while compressing
gzip -k application.log
41. zip/unzip – Create ZIP Archives
# Create zip archive
zip -r app-backup.zip /opt/myapp
# Extract zip archive
unzip app-backup.zip
# List zip contents
unzip -l app-backup.zip
Permission and Ownership
42. chmod – Change File Permissions
# Set permissions using octal notation
chmod 755 script.sh
# Add execute permission
chmod +x deploy.sh
# Remove write permission for group and others
chmod go-w config.yml
# Recursive permission change
chmod -R 644 /opt/myapp/config/
43. chown – Change File Ownership
# Change owner and group
chown nginx:nginx /var/www/html
# Change owner only
chown jenkins deploy.sh
# Recursive ownership change
chown -R app:app /opt/myapp
44. chgrp – Change Group Ownership
# Change group ownership
chgrp developers project-files
# Recursive group change
chgrp -R ops /opt/monitoring
System Information
45. uname – System Information
# Show all system information
uname -a
# Show kernel version
uname -r
# Show machine architecture
uname -m
46. uptime – System Uptime and Load
# Show uptime and load average
uptime
# Show uptime in pretty format
uptime -p
47. whoami – Current User
# Show current username
whoami
# Show user and group information
id
Understanding Linux permissions is vital for security. Learn how chmod, chown, and umask work with this guide on file permissions.
Log Analysis
48. journalctl – Systemd Journal
# Show all logs
journalctl
# Show logs for specific service
journalctl -u nginx
# Follow logs in real-time
journalctl -f
# Show logs since yesterday
journalctl --since yesterday
# Show only error priority logs
journalctl -p err
49. dmesg – Kernel Messages
# Show kernel messages
dmesg
# Show recent messages
dmesg | tail
# Filter by facility
dmesg --facility=daemon
Advanced DevOps Commands
50. crontab – Schedule Tasks
# Edit cron jobs
crontab -e
# List cron jobs
crontab -l
# Remove all cron jobs
crontab -r
# Edit cron jobs for specific user
crontab -u username -e
Automate tasks using crontab for recurring jobs or at for one-time execution. Crontab Guru is especially helpful for testing and writing cron expressions.
Command Combinations for DevOps Workflows
Monitoring and Alerting
# Check if service is running and restart if needed
systemctl is-active nginx || systemctl restart nginx
# Monitor log for specific errors
tail -f /var/log/application.log | grep -i error
# Find processes consuming high CPU
ps aux --sort=-%cpu | head -10
# Check disk usage and alert if over 80%
df -h | awk '$5 > 80 {print $0}'
Deployment Automation
# Create deployment backup
tar -czf "backup-$(date +%Y%m%d-%H%M%S).tar.gz" /opt/myapp
# Deploy new version with rollback capability
cp -r /opt/myapp /opt/myapp.backup.$(date +%Y%m%d) && \
tar -xzf new-version.tar.gz -C /opt/myapp
# Check application health after deployment
curl -f http://localhost:8080/health || echo "Deployment failed"
Log Analysis and Debugging
# Find top 10 IP addresses in access log
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -nr | head -10
# Search for errors in the last hour
find /var/log -name "*.log" -mmin -60 -exec grep -l "ERROR" {} \;
# Monitor real-time log with filtering
tail -f /var/log/application.log | grep --line-buffered -v "DEBUG"
Best Practices for DevOps Engineers
1. Always Use Full Paths in Scripts
# Good
/usr/bin/systemctl restart nginx
# Avoid
systemctl restart nginx
2. Implement Proper Error Handling
#!/bin/bash
set -euo pipefail # Exit on error, undefined variables, pipe failures
if ! systemctl is-active nginx > /dev/null; then
echo "Nginx is not running, starting..."
systemctl start nginx
fi
3. Use Logging and Timestamps
# Add timestamps to deployment logs
echo "$(date '+%Y-%m-%d %H:%M:%S') - Starting deployment" >> /var/log/deployment.log
4. Implement Health Checks
# Verify service health before proceeding
curl -f http://localhost:8080/health || {
echo "Service health check failed"
exit 1
}
Command Explanations and Real-World Use Cases
Top 5 File Management Commands
1. find – Advanced File Search
Syntax: find [path] [options] [expression] Explanation: The most powerful file search tool in Linux. Goes beyond simple filename matching to search by size, date, permissions, and content.
# Find all log files modified in last 24 hours
find /var/log -name "*.log" -mtime -1
# Find files larger than 100MB to clean up disk space
find /opt -size +100M -type f -exec ls -lh {} \;
# Find and delete temporary files older than 7 days
find /tmp -name "*.tmp" -mtime +7 -delete
DevOps Use Case: Essential for cleanup scripts, finding configuration files across deployments, and locating large files consuming disk space.
2. tar – Archive and Backup
Syntax: tar [options] archive-name files/directories Explanation: Creates compressed archives for backups and deployments. Preserves file permissions and directory structure.
# Create timestamped backup before deployment
tar -czf "app-backup-$(date +%Y%m%d-%H%M%S).tar.gz" /opt/myapp
# Extract with progress display
tar -xzf backup.tar.gz --verbose
# List archive contents without extracting
tar -tzf backup.tar.gz | head -10
DevOps Use Case: Automated backups, application deployments, and creating release packages with proper versioning.
3. rsync – Intelligent File Synchronization
Syntax: rsync [options] source destination Explanation: Efficiently synchronizes files and directories, only transferring changed portions. Superior to cp for large datasets.
# Sync local directory to remote server
rsync -av --progress /local/app/ user@server:/opt/app/
# Backup with deletion of removed files
rsync -av --delete /source/ /backup/
# Dry run to preview changes
rsync -av --dry-run /source/ /dest/
DevOps Use Case: Code deployments, server migrations, and creating mirror environments while minimizing transfer time.
4. chmod – Permission Management
Syntax: chmod [options] mode file/directory Explanation: Controls file access permissions critical for security. Uses octal notation (755) or symbolic (u+x).
# Set script executable for deployment
chmod +x deploy.sh
# Secure configuration files (owner read/write only)
chmod 600 /etc/myapp/database.conf
# Set proper web directory permissions
chmod -R 755 /var/www/html
DevOps Use Case: Securing sensitive configuration files, making deployment scripts executable, and setting proper web server permissions.
5. ln – Create Links (Symbolic and Hard)
Syntax: ln [options] target link-name Explanation: Creates links between files. Symbolic links (-s) are shortcuts; hard links are multiple names for same file.
# Create symbolic link for current application version
ln -sf /opt/myapp-v2.1.0 /opt/myapp-current
# Link configuration to standard location
ln -s /opt/myapp/config/app.conf /etc/myapp.conf
# Create backup hard link before modification
ln important-config.yml important-config.yml.backup
DevOps Use Case: Blue-green deployments, configuration management, and creating atomic application switches.
Top 5 Process and Network Commands
1. systemctl – Service Management
Syntax: systemctl [command] [service-name] Explanation: Controls systemd services – the modern way to manage daemons, services, and system state.
# Start service and enable auto-start
systemctl start nginx && systemctl enable nginx
# Check service status with detailed output
systemctl status postgresql --no-pager
# Reload configuration without restart
systemctl reload nginx
# Show failed services for troubleshooting
systemctl --failed
DevOps Use Case: Managing application services, database servers, and monitoring daemons across multiple environments.
2. ss – Socket Statistics (Modern netstat)
Syntax: ss [options] [filter] Explanation: Displays network connections, routing tables, and interface statistics. Faster and more detailed than netstat.
# Show all listening TCP services with processes
ss -tlnp
# Monitor established connections to specific port
ss -tn state established '( dport = :80 or sport = :80 )'
# Show socket summary statistics
ss -s
# Find process using specific port
ss -tlnp | grep :3306
DevOps Use Case: Network troubleshooting, security audits, and monitoring application connectivity.
3. curl – HTTP Client for APIs
Syntax: curl [options] URL Explanation: Versatile tool for testing APIs, downloading files, and automating HTTP requests. Essential for health checks.
# Health check with timeout and status code
curl -f -m 10 https://api.myapp.com/health || echo "Service down"
# POST JSON data to API
curl -X POST -H "Content-Type: application/json" \
-d '{"deployment":"v1.2.0"}' https://webhook.example.com
# Download with progress bar and retry
curl -L --progress-bar --retry 3 -o app.tar.gz https://releases.example.com/app-v1.2.tar.gz
DevOps Use Case: API testing, deployment webhooks, health monitoring, and automated file downloads.
4. ps – Process Information
Syntax: ps [options] Explanation: Shows running processes with detailed information about CPU, memory usage, and process hierarchy.
# Show all processes with full details
ps aux --sort=-%cpu | head -20
# Monitor specific application processes
ps -ef | grep java | grep myapp
# Show process tree to understand relationships
ps auxf
# Find memory-heavy processes
ps aux --sort=-%mem | head -10
DevOps Use Case: Performance troubleshooting, resource monitoring, and identifying problematic processes.
5. kill/killall – Process Termination
Syntax: kill [signal] PID or killall [options] process-name Explanation: Terminates processes gracefully (TERM) or forcefully (KILL). Critical for service management and recovery.
# Graceful shutdown with cleanup
kill -TERM $(pgrep java | head -1)
# Force kill unresponsive process
kill -9 1234
# Restart service by killing all instances
killall nginx && systemctl start nginx
# Kill processes matching pattern
pkill -f "java.*myapp"
DevOps Use Case: Service restarts, handling hung processes, and emergency recovery procedures.
Top 5 DevOps and Automation Commands
1. crontab – Task Scheduling
Syntax: crontab [options] Explanation: Schedules automated tasks to run at specific times. The backbone of system automation and maintenance.
# Edit current user's cron jobs
crontab -e
# Example entries for automation:
# Daily backup at 2 AM
0 2 * * * /opt/scripts/backup.sh >> /var/log/backup.log 2>&1
# Health check every 5 minutes
*/5 * * * * curl -f http://localhost:8080/health || /opt/scripts/restart-app.sh
# Weekly log rotation on Sundays
0 3 * * 0 /opt/scripts/rotate-logs.sh
DevOps Use Case: Automated backups, log rotation, health monitoring, and scheduled maintenance tasks.
2. grep – Pattern Matching and Log Analysis
Syntax: grep [options] pattern [files] Explanation: Searches text patterns in files. Essential for log analysis, configuration management, and troubleshooting.
# Find errors in application logs
grep -i "error\|exception\|fatal" /var/log/myapp/*.log
# Count specific events
grep -c "successful login" /var/log/auth.log
# Show context around errors
grep -A 5 -B 5 "OutOfMemoryError" /var/log/application.log
# Real-time log monitoring
tail -f /var/log/nginx/access.log | grep -E "5[0-9]{2}"
DevOps Use Case: Log analysis, error tracking, security monitoring, and real-time troubleshooting.
3. awk – Data Processing and Reporting
Syntax: awk 'pattern { action }' file Explanation: Programming language for text processing. Excellent for parsing logs, generating reports, and data extraction.
# Extract IP addresses from access logs
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -nr
# Calculate total response times
awk '{sum += $10} END {print "Average response time:", sum/NR "ms"}' access.log
# Parse CSV and filter data
awk -F',' '$3 > 100 {print $1, $2}' metrics.csv
# Generate simple report
awk '{users[$1]++} END {for (user in users) print user, users[user]}' login.log
DevOps Use Case: Log analysis, performance reporting, data extraction from structured logs, and generating metrics.
4. sed – Stream Editing and Configuration Management
Syntax: sed [options] 'command' file Explanation: Stream editor for filtering and transforming text. Perfect for configuration updates and automated file modifications.
# Update configuration during deployment
sed -i 's/debug=true/debug=false/g' /opt/myapp/config.yml
# Replace database connection string
sed -i 's/localhost:3306/prod-db:3306/g' application.properties
# Remove sensitive data from logs
sed 's/password=[^&]*/password=****/g' application.log
# Add configuration entry after specific line
sed -i '/\[database\]/a timeout=30' config.ini
DevOps Use Case: Configuration management, environment-specific deployments, log sanitization, and automated file updates.
5. journalctl – Systemd Log Management
Syntax: journalctl [options] [matches] Explanation: Query and display systemd journal logs. Modern alternative to traditional syslog with advanced filtering and real-time monitoring.
# Follow specific service logs in real-time
journalctl -u nginx -f
# Show logs from last deployment
journalctl --since "2025-07-29 10:00:00" --until "2025-07-29 11:00:00"
# Filter by priority (errors only)
journalctl -p err
# Show boot logs for system issues
journalctl -b -1
# Export logs in JSON format for analysis
journalctl -u myapp -o json | jq .
DevOps Use Case: Service troubleshooting, deployment monitoring, system diagnostics, and centralized logging analysis.
To explore any command in depth, use the online Linux man pages or refer to the Linux Documentation Project for comprehensive guides.
📋 Want the complete command reference? Download our comprehensive PDF guide with all 50 commands, advanced examples, and troubleshooting scenarios: Download linux commands for devops pdf
Complete Quick Reference Cheat Sheet
File and Directory Operations
| Command | Syntax | Purpose |
|---|---|---|
ls | ls -la | List files with details and permissions |
cd | cd /path or cd ~ | Change directory or go home |
pwd | pwd | Print current working directory |
mkdir | mkdir -p /path/to/dir | Create directories recursively |
cp | cp -r source dest | Copy files/directories recursively |
mv | mv old new | Move or rename files |
rm | rm -rf /path | Remove files/directories forcefully |
find | find /path -name "*.log" | Search files by pattern |
locate | locate filename | Quick file search (indexed) |
which | which command | Find executable location |
Process Management
| Command | Syntax | Purpose |
|---|---|---|
ps | ps aux | Show all running processes |
top | top | Real-time process monitor |
htop | htop | Enhanced interactive process viewer |
kill | kill -9 PID | Force terminate process |
killall | killall nginx | Kill processes by name |
pkill | pkill -f "pattern" | Kill processes by pattern |
nohup | nohup command & | Run command in background |
jobs | jobs | Show background jobs |
systemctl | systemctl restart service | Manage system services |
System Monitoring
| Command | Syntax | Purpose |
|---|---|---|
df | df -h | Show disk usage human-readable |
du | du -h /path | Show directory size |
free | free -h | Display memory usage |
iostat | iostat -x 2 | I/O statistics every 2 seconds |
sar | sar -u | System activity report |
vmstat | vmstat 2 | Virtual memory statistics |
lscpu | lscpu | Display CPU information |
uptime | uptime | System uptime and load |
whoami | whoami | Show current user |
Network Operations
| Command | Syntax | Purpose |
|---|---|---|
netstat | netstat -tuln | Show listening ports |
ss | ss -tlnp | Modern netstat replacement |
curl | curl -I https://site.com | Test HTTP endpoints |
wget | wget -O file.tar.gz url | Download files |
ping | ping -c 4 google.com | Test connectivity |
traceroute | traceroute google.com | Trace network path |
dig | dig google.com MX | DNS lookup queries |
nslookup | nslookup google.com | DNS resolution |
Text Processing
| Command | Syntax | Purpose |
|---|---|---|
grep | grep -r "ERROR" /var/log/ | Search text patterns |
awk | awk '{print $1}' file | Process columns and data |
sed | sed 's/old/new/g' file | Stream editor for text |
sort | sort -n file | Sort lines numerically |
uniq | uniq -c file | Remove duplicates, count |
wc | wc -l file | Count lines, words, chars |
head | head -n 20 file | Show first N lines |
tail | tail -f file | Follow file changes |
cut | cut -d',' -f2 file.csv | Extract columns |
tr | tr '[:lower:]' '[:upper:]' | Transform characters |
Archive and Compression
| Command | Syntax | Purpose |
|---|---|---|
tar | tar -czf backup.tar.gz /path | Create compressed archive |
tar | tar -xzf backup.tar.gz | Extract archive |
gzip | gzip file.txt | Compress single file |
gunzip | gunzip file.txt.gz | Decompress gzip file |
zip | zip -r archive.zip /path | Create ZIP archive |
unzip | unzip archive.zip | Extract ZIP archive |
Permissions and Ownership
| Command | Syntax | Purpose |
|---|---|---|
chmod | chmod 755 file | Change file permissions |
chown | chown user:group file | Change ownership |
chgrp | chgrp group file | Change group ownership |
umask | umask 022 | Set default permissions |
Log Analysis
| Command | Syntax | Purpose |
|---|---|---|
journalctl | journalctl -u nginx | View systemd service logs |
journalctl | journalctl -f | Follow journal logs |
dmesg | dmesg | tail | Kernel messages |
logger | logger "Custom message" | Write to system log |
Advanced Operations
| Command | Syntax | Purpose |
|---|---|---|
crontab | crontab -e | Edit scheduled tasks |
at | at now + 1 hour | Schedule one-time task |
rsync | rsync -av src/ dest/ | Sync files/directories |
scp | scp file user@host:/path | Secure copy over SSH |
ssh | ssh user@hostname | Secure shell connection |
sudo | sudo command | Execute as another user |
su | su - user | Switch user |
mount | mount /dev/sdb1 /mnt | Mount filesystem |
umount | umount /mnt | Unmount filesystem |
Essential Command Combinations
| Purpose | Command Combination |
|---|---|
| Find large files | find / -size +100M -type f -exec ls -lh {} \; |
| Monitor real-time logs | tail -f /var/log/app.log | grep ERROR |
| Top CPU processes | ps aux --sort=-%cpu | head -10 |
| Top memory processes | ps aux --sort=-%mem | head -10 |
| Find open files by process | lsof -p PID |
| Network connections | ss -tuln | grep :80 |
| Disk usage by directory | du -h /var/log | sort -hr |
| Count files in directory | find /path -type f | wc -l |
| Remove old files | find /tmp -mtime +7 -delete |
| Backup with timestamp | tar -czf backup-$(date +%Y%m%d).tar.gz /data |
Permission Quick Reference
| Permission | Octal | Binary | Meaning |
|---|---|---|---|
--- | 0 | 000 | No permissions |
--x | 1 | 001 | Execute only |
-w- | 2 | 010 | Write only |
-wx | 3 | 011 | Write and execute |
r-- | 4 | 100 | Read only |
r-x | 5 | 101 | Read and execute |
rw- | 6 | 110 | Read and write |
rwx | 7 | 111 | Read, write, and execute |
Common Port Numbers
| Port | Service | Protocol |
|---|---|---|
| 22 | SSH | TCP |
| 53 | DNS | TCP/UDP |
| 80 | HTTP | TCP |
| 443 | HTTPS | TCP |
| 3306 | MySQL | TCP |
| 5432 | PostgreSQL | TCP |
| 6379 | Redis | TCP |
| 8080 | Alt HTTP | TCP |
| 9200 | Elasticsearch | TCP |
Signal Reference
| Signal | Number | Purpose |
|---|---|---|
| TERM | 15 | Graceful termination (default) |
| KILL | 9 | Force termination |
| HUP | 1 | Reload configuration |
| INT | 2 | Interrupt (Ctrl+C) |
| QUIT | 3 | Quit with core dump |
| USR1 | 10 | User-defined signal 1 |
| USR2 | 12 | User-defined signal 2 |
Conclusion
Mastering these 50 Linux Commands for DevOps will significantly enhance your effectiveness as a DevOps engineer. These commands form the foundation for automation scripts, monitoring solutions, and daily operational tasks. Practice combining these commands to create powerful one-liners and scripts that can automate repetitive tasks and solve complex problems.
Remember to always test commands in a safe environment before using them in production, and implement proper error handling and logging in your automation scripts.
Frequently Asked Questions
What are essential Linux commands for DevOps?
The most essential Linux commands for DevOps engineers include systemctl for service management, ps and top for process monitoring, grep and awk for log analysis, curl and wget for network operations, tar for backups, and find for file operations. These commands form the foundation for automation, monitoring, and troubleshooting in DevOps workflows.
How to use systemctl to restart services?
To restart a service using systemctl, use the command systemctl restart service-name. For example, systemctl restart nginx restarts the Nginx service. You can also use systemctl reload nginx for configuration reloads, systemctl status nginx to check status, and systemctl enable nginx to enable auto-start at boot.
What’s the difference between grep, awk, and sed?
grep: Searches for patterns in text files. Best for finding specific strings or regex patterns.
awk: A programming language for text processing. Excellent for column-based data manipulation and calculations.
sed: A stream editor for filtering and transforming text. Ideal for find-and-replace operations and line-based editing.
How to monitor system performance in Linux?
Use commands like top or htop for real-time process monitoring, iostat for I/O statistics, free -h for memory usage, df -h for disk space, and sar for historical system activity. Combine these with vmstat for virtual memory statistics and netstat or ss for network monitoring.
What’s the best way to search for files in Linux?
Use find for comprehensive searches: find /path -name "filename" for exact matches, find /path -name "*.log" for patterns, or find /path -mtime -1 for recently modified files. For faster searches of indexed files, use locate filename after running updatedb.
How to manage processes in Linux for DevOps?
Use ps aux to list all processes, kill -TERM PID for graceful termination, kill -9 PID for force kill, nohup command & to run processes in background, and systemctl for service management. Monitor with top or htop and use pkill or killall for killing by name.
What are the most important log analysis commands?
Key log analysis commands include tail -f for real-time log monitoring, grep -r "ERROR" /var/log/ for error searching, awk '{print $1}' logfile | sort | uniq -c for counting occurrences, journalctl -u service-name for systemd logs, and sed for log filtering and processing.
How to check network connectivity and troubleshoot issues?
Use ping to test basic connectivity, traceroute to trace network paths, dig or nslookup for DNS resolution, netstat -tuln or ss -tuln to check listening ports, curl -I to test HTTP endpoints, and tcpdump for packet analysis. Check firewall status with iptables -L or ufw status.
What’s the proper way to handle file permissions in DevOps?
Use chmod to change permissions (e.g., chmod 755 script.sh), chown to change ownership (chown user:group file), and ls -la to view current permissions. Follow the principle of least privilege, use specific numeric permissions (755 for executables, 644 for files, 600 for sensitive data), and implement proper group management.
How to automate tasks using Linux commands?
Create shell scripts combining commands, use crontab -e for scheduled tasks, implement error handling with set -e in scripts, use && and || for conditional execution, and combine commands with pipes (|) for data processing. Always test scripts in non-production environments first.
What are the best practices for using Linux commands in production?
Always use absolute paths in scripts, implement proper error handling and logging, test commands in staging first, use version control for scripts, implement rollback procedures, monitor command execution with appropriate logging, and follow security best practices with proper user permissions and sudo usage.
How to compress and archive files efficiently?
Use tar -czf archive.tar.gz directory/ to create compressed archives, tar -xzf archive.tar.gz to extract, gzip file for single file compression, and zip -r archive.zip directory/ for ZIP format. For automated backups, include timestamps: tar -czf backup-$(date +%Y%m%d).tar.gz /path/.
Want to improve your DevOps skills further? Check out our other guides on CI/CD best practices, Infrastructure as Code, and Container orchestration.
Keywords: Linux commands DevOps, DevOps engineer commands, Linux administration, system monitoring commands, process management Linux, network troubleshooting commands, log analysis Linux, DevOps automation, server management commands, Linux cheat sheet DevOps

One Comment