DEV Community

Kai Norden
Kai Norden

Posted on

5 Shell One-Liners That Replaced My Python Scripts

I used to write Python scripts for everything. Then I discovered these shell one-liners that do the same job in seconds.

1. Find and kill zombie processes

ps aux | awk '$8 ~ /Z/ {print $2}' | xargs -r kill -9
Enter fullscreen mode Exit fullscreen mode

No more writing process managers. This finds all zombie processes and kills them.

2. Watch a log file with color highlighting

tail -f /var/log/app.log | sed 's/ERROR/\x1b[31m&\x1b[0m/g; s/WARN/\x1b[33m&\x1b[0m/g'
Enter fullscreen mode Exit fullscreen mode

Errors in red, warnings in yellow. No need for lnav or custom log viewers.

3. Quick HTTP server with directory listing

python3 -m http.server 8080 --bind 127.0.0.1
Enter fullscreen mode Exit fullscreen mode

Okay, this one uses Python but it is a one-liner. Perfect for sharing files on your local network.

4. Find large files eating your disk

find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null | sort -k5 -h -r | head -20
Enter fullscreen mode Exit fullscreen mode

Instantly see the 20 largest files on your system. Saved me from buying more storage twice.

5. Monitor any website for changes

watch -n 60 -d "curl -s https://example.com | md5sum"
Enter fullscreen mode Exit fullscreen mode

Refreshes every 60 seconds, highlights when the hash changes. Poor mans uptime monitor.

Bonus: JSON pretty-print from clipboard

pbpaste | python3 -m json.tool | pbcopy
Enter fullscreen mode Exit fullscreen mode

macOS only. Paste ugly JSON, get pretty JSON back in your clipboard.


These replaced about 500 lines of Python across various utility scripts. The shell is underrated.

What are your favorite one-liners? I am always collecting new ones.

Top comments (0)