12 Must-Know Linux command for DevOps Beginners to Boost Efficiency (With Examples)

Linux is a powerful tool used by DevOps engineers to manage servers, fix problems, and automate tasks. Learning a few key commands can make your work easier and faster. This article explains 12 simple Linux commands with real-life examples that beginners can understand and use.
1. grep – Find Words in Files
What It Does: Searches for specific words in files, like finding "error" in a log file.
Example: Your website has errors, and you want to check the server logs.
Command:
grep -i "error" /var/log/nginx/error.log
-i: Ignores if the word is in uppercase or lowercase (finds "Error" or "ERROR").
Try This:Look for "404" errors:
grep "404" /var/log/nginx/access.log
2. chmod & chown – Control File Access
What They Do: chmod changes who can use a file; chown changes who owns it.
Example: Your script deploy.sh isn’t working because it lacks permission.
Commands:
chmod +x deploy.sh # Makes the script runnable
chown root:root deploy.sh # Sets the owner to "root"
Why It’s Useful:
- Secure files like SSH keys:
chmod 600 ~/.ssh/id_rsastops others from reading them.
3. curl – Test Websites and APIs
What It Does: Checks if a website or API is working by sending requests.
Example: Your app’s payment system is slow. Test if it responds.
Command:
curl -X GET https://api.yoursite.com/payments -H "Authorization: Bearer YOUR_TOKEN"
Fun Tip:
Check how fast a website loads:
curl -o /dev/null -s -w '%{time_total}s\n' https://google.com
4. rsync – Copy Files Safely
What It Does: Copies files between computers or servers while keeping them safe.
Example: Back up your website files to another server.
Command:
rsync -avz /var/www/html/ user@backup-server:/backup/
-a: Keeps file details like permissions.-v: Shows what’s copying.-z: Makes the transfer faster by compressing files.
5. systemctl – Manage Services
What It Does: Starts, stops, or checks services like web servers.
Example: Your Nginx web server stops working. Restart it.
Commands:
sudo systemctl restart nginx # Restarts Nginx
sudo systemctl status nginx # Checks if it’s running
Good to Know:
- Make Nginx start automatically:
sudo systemctl enable nginx.
6. awk – Pull Out Data
What It Does: Extracts specific information from a list, like usernames or CPU usage.
Example: Find which user is using too much CPU.
Command:
ps aux | awk '{print $1, $3}' | sort -k2 -nr | head -n 5
What It Means:
ps aux: Shows all running programs.awk: Picks username and CPU usage.sortandhead: Lists the top 5 users using the most CPU.
7. cron – Schedule Tasks
What It Does: Runs tasks automatically at set times, like cleaning old files.
Example: Delete old logs every Sunday at midnight.
Commands:
# Open the cron editor
crontab -e
# Add this line
0 0 * * 0 /usr/bin/find /var/log -name "*.log" -mtime +7 -delete
What It Does:
- Runs every Sunday (
0 0 * * 0) to delete logs older than 7 days.
8. lsof – Check Open Ports
What It Does: Shows which program is using a specific port.
Example: Port 8080 is blocked, and you need to find out why.
Command:
sudo lsof -i :8080
Example Output:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 1234 root 21u IPv4 23456 0t0 TCP *:8080 (LISTEN)
What It Means: A Node.js program (PID 1234) is using port 8080.
9. journalctl – Read System Logs
What It Does: Shows logs to help you understand why something went wrong.
Example: Your server restarted suddenly. Find out why.
Command:
journalctl -u systemd-logind --since "10 minutes ago"
-u: Looks at logs for a specific service.Another Use: Check kernel logs with
journalctl -k.
10. tar – Pack and Unpack Files
What It Does: Combines files into one archive or extracts them.
Example: Send a project folder to another server.
Commands:
tar -czvf app.tar.gz /home/project # Packs the folder
tar -xzvf app.tar.gz -C /var/www # Unpacks it
-c: Creates an archive.-x: Extracts files.-z: Compresses to save space.-v: Shows what’s happening.
find– Search for Files
What It Does: Searches for files or folders based on name, size, or other criteria.
Example: You need to find all log files in the /var/log folder.
Command:
find /var/log -name "*.log"
What It Means:
/var/log: Where to search.-name "*.log": Looks for files ending in.log.
Another Example: Find files larger than 100MB:
find / -type f -size +100M
-type f: Only finds files (not folders).-size +100M: Files bigger than 100MB.
Why It’s Useful: Helps locate specific files to clean up space or troubleshoot issues.
du– Check Disk Space UsageWhat It Does: Shows how much space files or folders are using.
Example: You want to see how much space the/var/logfolder is taking.
Command:du -sh /var/logExplanation:
-s: Summarizes the total size.-h: Shows the size in a readable format (e.g., MB or GB).
Another Example: Check the size of all folders in/home:
du -h /home | sort -h
sort -h: Lists folders from smallest to largest size.
Why It Helps: Helps you find which files or folders are using too much disk space.
Bonus: Handy Command Combos
Find High CPU Usage:
top -c # Find the program’s PID strace -p <PID> # See what it’s doingFind Big Files:
find / -type f -size +100M -exec ls -lh {} \;Check Disk Space Every 5 Seconds:
watch -n 5 df -h
Final Words
These 12 Linux commands are super useful for DevOps beginners. They help you fix problems, manage servers, and save time. Try them out, practice with the examples, and you’ll soon feel confident using Linux!




