Why Every Developer Should Learn Linux
The cloud runs on Linux. Docker runs on Linux. The internet runs on Linux. If you want to understand how software really works, you need to be comfortable in the shell.
1. The Power of the Pipe |#
The United Philosophy: Write programs that do one thing and do it well. Write programs to work together.
Example: Find the 5 most common words in a text file.
cat essay.txt | tr -cs A-Za-z '\n' | tr A-Z a-z | sort | uniq -c | sort -rn | head -n 5Try doing that in a GUI.
2. Essential Commands for DevOps#
grep: Search text like a wizard.grep -r "TODO" .(Find all TODOs in current directory)
htop: Monitor system resources.ssh: Connect to remote servers securely.rsync: The robust file copier.rsync -avz local/ remote:/path/
Challenge: Spend one week executing file operations (copy, move, delete) ONLY via the terminal. You’ll never go back to drag-and-drop.
3. Permissions 101#
r(Read): 4w(Write): 2x(Execute): 1
chmod 755 script.sh means:
- Owner: 7 (4+2+1) -> Read, Write, Execute
- Group: 5 (4+1) -> Read, Execute
- Others: 5 (4+1) -> Read, Execute
4. Bash Scripting: Automating the Boring Stuff#
You don’t need Python for everything. Sometimes a 5-line bash script is better.
Example: Log Rotator#
#!/bin/bash
LOG_DIR="/var/log/myapp"
DAYS_TO_KEEP=7
# Find files older than 7 days and delete them
find $LOG_DIR -name "*.log" -mtime +$DAYS_TO_KEEP -delete
echo "Cleanup complete."Example: Site Monitor#
#!/bin/bash
URL="https://mysite.com"
STATUS=$(curl -o /dev/null -s -w "%{http_code}\n" $URL)
if [ "$STATUS" != "200" ]; then
echo "Site is down! Status: $STATUS" | mail -s "Alert" me@example.com
fi5. Systemd: Ensuring Uptime#
Don’t run your apps in a screen session. Create a systemd service.
/etc/systemd/system/myapp.service
[Unit]
Description=My Python App
After=network.target
[Service]
User=www-data
WorkingDirectory=/var/www/myapp
ExecStart=/var/www/myapp/venv/bin/gunicorn app:app
Restart=always
[Install]
WantedBy=multi-user.targetNow you have automatic restarts, logging, and dependency management.