Site icon New Generation Enterprise Linux

Stop running shell loops when parallel does it better

Shell Scripting / Bash Tricks

Stop running shell loops when parallel does it better

đź§© The Challenge

Dealing with a folder full of thousands of logs that need to be compressed is a nightmare if you’re just looping through them one by one. You end up watching a single CPU core hit 100% while the rest of your server just sits there loafing around.

đź’ˇ The Fix

Use GNU Parallel to blast through that queue across all your available cores. It turns a ten-minute wait into a ten-second job without rewriting your entire script.

find . -maxdepth 1 -name "*.log" | parallel gzip

⚙️ Why It Works

This command pipes the file list directly into parallel, which then spawns a separate gzip instance for every thread it can safely handle. It handles the scheduling so you don’t overwhelm your I/O.

🚀 Pro-Tip: Add –bar to the command if you want to see a progress indicator so you aren’t just staring at a blinking cursor.

Linux Tips & Tricks | © ngelinux.com | 9/11/2026

0 0 votes
Article Rating
Exit mobile version