Introduction
As a DevOps engineer, mastering Linux is non-negotiable. Whether you’re deploying microservices, debugging performance issues, managing cloud infrastructure, or building CI/CD pipelines, Linux commands are at the core of your workflow. This guide walks you through 35 essential Linux commands, each with real-world use cases tailored for DevOps.
🔧 File & Directory Operations
ls– List files and directories.ls -lahshows file sizes and permissions.
cd– Change directories.- Navigate efficiently in scripts:
cd /var/www/html.
- Navigate efficiently in scripts:
pwd– Print working directory.- Useful for debugging scripts.
mkdir– Create directories.- Example:
mkdir -p /opt/myapp/logscreates nested folders.
- Example:
touch– Create empty files.- Used to create
.envor placeholder files in pipelines.
- Used to create
rm– Remove files and directories.- Caution:
rm -rf /some/pathcan be destructive. Automate cleanup jobs.
- Caution:
cp– Copy files and directories.- Example:
cp config.yaml config.yaml.bakbefore updates.
- Example:
mv– Move or rename files.- Use in deployment steps:
mv new.html index.html
- Use in deployment steps:
find– Search for files.find /var/log -name "*.log"to identify large log files.
du– Estimate file space usage.du -sh *shows space used by directories.
📁 File Viewing & Manipulation
cat– View file contents.- Combine with
grepfor quick searches.
- Combine with
less/more– Page through text.less /var/log/syslogto view logs comfortably.
head/tail– View the start or end of files.tail -f /var/log/nginx/access.logfor live logs.
grep– Search text with patterns.- Example:
grep "ERROR" /var/log/app.log
- Example:
awk– Pattern scanning and data extraction.- Real use:
awk -F":" '{ print $1 }' /etc/passwdto list usernames.
- Real use:
sed– Stream editor for modifying files.- Replace text in files:
sed -i 's/foo/bar/g' config.txt
- Replace text in files:
cut– Extract fields from text.cut -d':' -f1 /etc/passwd
sort– Sort lines in text files.- Useful in processing pipeline logs or output.
uniq– Filter out repeated lines.sort data.txt | uniq -cshows duplicates.
🔐 Permissions & Ownership
chmod– Change file permissions.chmod 755 script.shmakes it executable.
chown– Change file owner and group.chown www-data:www-data /var/www/html -R
umask– Set default permissions.- Often set in init scripts.
stat– Display detailed file info.- Helps in debugging file access issues.
📊 Process & Resource Management
ps– Display current processes.ps aux | grep nginxto locate specific services.
top/htop– Monitor system resource usage.htopis interactive and user-friendly.
kill/killall– Terminate processes.kill -9 <PID>to forcefully stop rogue processes.
nice/renice– Set process priority.- Adjust priority for resource-hungry tasks.
lsof– List open files.- Debug file locks:
lsof | grep deleted
- Debug file locks:
strace– Trace system calls.- Debug startup issues:
strace ./myapp
- Debug startup issues:
🚀 Networking & Troubleshooting
curl– Transfer data to/from a server.- Test APIs:
curl -X POST -d '{}' https://api.example.com
- Test APIs:
wget– Non-interactive file download.wget https://downloads.example.com/tool.sh
netstat/ss– Network statistics.ss -tulnpshows listening ports.
tcpdump– Capture network traffic.- Debug latency:
tcpdump -i eth0 port 80
- Debug latency:
ping/traceroute– Network connectivity.- Identify broken routes or DNS issues.
🔄 Automation & Scripting
xargs– Build and execute commands from input.- Bulk operations:
cat urls.txt | xargs wget
- Bulk operations:
🔹 Real DevOps Use Case Highlights:
- Using
awkin CI/CD: Extract version info from files and pass it to Docker. lsofto troubleshoot: Find services holding deleted files and causing disk bloat.sedin automation: Replace environment variables during deployment.tail -fin monitoring: View live logs in Kubernetes pods.xargsfor batch tasks: Automate bulk log rotation or file downloads.
Conclusion
Mastering these 35 Linux commands will not only boost your productivity but also help you troubleshoot and automate your infrastructure with confidence. Bookmark this list and start integrating these commands into your daily workflow. Want more DevOps content? Follow me on LinkedIn and stay tuned for upcoming posts on Ansible, Docker, Kubernetes, and Terraform!


