Steve Litt on 29 Jul 2015 22:50:25 -0700

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] xargs guide

On Wed, 29 Jul 2015 22:48:27 -0400
Walt Mankowski <> wrote:

> On Wed, Jul 29, 2015 at 09:43:54PM -0400, Steve Litt wrote:
> > Hi all,
> > 
> > xargs is a gender-changer type program that adapts one program's
> > stdout to the next program's command line arguments. It's extremely
> > handy for shell scripting, but it can be tricky. I've written a
> > short guide for xargs that shows how to get around the usual xargs
> > landmines:
> > 
> >
> > 
> > Hope you like it.
> I also use xargs all the time.  This is a nice tutorial, but I have a
> few comments on it:
> * There's a typo on the very first line. It should be "Its", not
>   "It's".

Fixed. Thanks!

> * Why is the font so big?  I think it makes it hard to read.

I need to get more info from you about that offline. The short answer
is to satisfy Google's "Mobile Friendly" test, but there's a lot more
to it than that. I'll email you tomorrow with questions.

> * The image link below "The following diagram illustrates the adapter
>   idea" is broken.

Fixed. Thanks!

> * I found it interesting that you put such an emphasis on
>   --max-lines=1.  I've never used that option.  I didn't even know
>   that WAS an option.  The main reason I use xargs is to construct
>   giant command lines.
>   Here's an example.  Last week I had to change the permissions on a
>   large number of TIF files spread across dozens of subdirectories.
>   The first thing I tried was
>   $ chmod 664 **/*.tif
>   but I got an error that my command line was too long.  Then I ran
>   $ find . | grep 'tif$' | wc
>   and saw that there were over 3 million files.  So I ran
>   $ find . | grep 'tif$' | xargs chmod 664
>   When you run it this way, xargs will call chmod repeatedly, each
>   time with as big of a command line as your system will support.
>   It's far more efficient than forking chmod for each of 3 million
>   files.


I think tomorrow or the next day I'll put in a whole section on this
subject. Before I do that, I have to investigate -0 and a few other
things to make sure that a space in a filename doesn't wreck the whole

> * I don't know how I missed the --max-procs parameter.  I'm definitely
>   going to have to try that out next time.

That will be good for when you can't just put multiple objects as
command line parameters the way you did with chmod 664.

Good eye, Walt. Thanks!


Steve Litt 
July 2015 featured book: Rapid Learning for the 21st Century
Philadelphia Linux Users Group         --
Announcements -
General Discussion  --