Stop passing massive lists of files to commands that choke on them

Shell Scripting / Bash Tricks

Stop passing massive lists of files to commands that choke on them

🧩 The Challenge

Trying to run chmod or chown on millions of small files usually ends with an Argument list too long error that ruins your day. You end up staring at a blinking cursor while your script just gives up.

💡 The Fix

Use xargs to feed those file paths to your command in bite-sized chunks instead of trying to pass them all at once. It handles the memory overhead so your shell doesn’t freak out.

find /var/www/html -type f -print0 | xargs -0 -n 1000 chmod 644

⚙️ Why It Works

The -print0 and -0 flags are the secret sauce here because they handle filenames with spaces or weird characters that would otherwise break your loop. xargs then bundles those names into batches so the underlying command never hits the kernel’s limit for argument size.

🚀 Pro-Tip: Use the -P flag with xargs if you want to run those processes in parallel and speed things up even more.

Linux Tips & Tricks | © ngelinux.com | 12/1/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted