Ritesh's Blog

Do batch things well

· rsinha

I sometimes forget this really easy one liner for doing things in a batch on Linux/MacOS.

# for file in `find . -type f`; do somescript.py $file; done

If you’re relying on the output of find it is probably best to use the xargs option to find like so:

# find . -type f -print0 | xargs -0 somescript.py

Even better, you can avoid using xargs, instead use the exec option to find. Although I think this is available only on newer versions of find.

# find . -type f -exec somescript.py '{}' +

Sure, I could’ve written the batch file handling feature as part of my script but why waste my time when there are existing tools that already do one thing well?

Reply to this post by email ↪