Michael Lazin on 29 Jul 2015 21:29:01 -0700 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: [PLUG] xargs guide |
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:
>
> http://www.troubleshooters.com/linux/xargs.htm
>
> 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".
* Why is the font so big? I think it makes it hard to read.
* The image link below "The following diagram illustrates the adapter
idea" is broken.
* 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 don't know how I missed the --max-procs parameter. I'm definitely
going to have to try that out next time.
Walt
___________________________________________________________________________
Philadelphia Linux Users Group -- http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug