BLU Discuss list archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Discuss] GNU xargs trick
- Subject: [Discuss] GNU xargs trick
- From: mbr at arlsoft.com (MBR)
- Date: Wed, 27 Apr 2016 13:14:53 -0400
- In-reply-to: <5de588b8-11f0-c674-843d-3f5ce878583a@gmail.com>
- References: <5de588b8-11f0-c674-843d-3f5ce878583a@gmail.com>
Very cool! I've used xargs for many years, but I never knew about the -I or -P options. Are they only in the GNU implementation, or have they been ported to other platforms? Mark Rosenthal On 4/27/16 10:25 AM, Rich Pieri wrote: > There is a trick to GNU xargs that lets you easily parallelize > processes. The particular use I discovered is for optimizing directories > full of PNG files using optipng. I first looked at GNU parallel but it's > way overkill for what I want. I found a couple of scripts that do some > tricks with & and lock files but those ran into problems with > complex-ish commands. Then I learned about the xargs trick: > > find . -name "*.png" -print | xargs -I{} -P 4 optipng -o1 -preserve {} > > The find part should be obvious, xargs maybe not so much. -I enables > substitution. Whenever the string following -I appears it is replaced > with the the line from stdin. -P 4 says to run a maximum of 4 processes; > the default is 1. Everything after is the optipng command with {} > replaced with each line from the find command. > > I dunnow if this has ever come up on the list but it's been quiet lately > and I figured it's a cool enough trick to share. >
- References:
- [Discuss] GNU xargs trick
- From: richard.pieri at gmail.com (Rich Pieri)
- [Discuss] GNU xargs trick
- Prev by Date: [Discuss] GNU xargs trick
- Next by Date: [Discuss] GNU xargs trick
- Previous by thread: [Discuss] GNU xargs trick
- Next by thread: [Discuss] Looking for a replacement RSS/Atom feed reader extension for use with Firefox
- Index(es):