l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2001 Dec 30 16:59

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] Red Hat Soundblaster Setup
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] Red Hat Soundblaster Setup

Pete mentioned:
> there's also something called xargs, which i never learned how to use.
> maybe someone on the list will explain how to use it.

xargs is pretty neat.  (Mike Simons taught me about it)

Instead of doing something like this:

  $ find . -name "*.html" -exec grep -i -l yahoo.com {} \;

(List (-l) all files named "[something].html" which contain the string
"yahoo.com", regardless of capitalization (-i))

Which would be the same as doing:

  $ grep -i -l yahoo.com ./foo.html
  $ grep -i -l yahoo.com ./bar.html
  $ grep -i -l yahoo.com ./baz.html
  $ grep -i -l yahoo.com ./index.html
  $ grep -i -l yahoo.com ./links.html
  $ grep -i -l yahoo.com ./users/bill/index.html
  $ grep -i -l yahoo.com ./users/pete/search.html
  ... etc.

... it can be more efficient to use xargs, like so:

  $ find . -name "*.html" | xargs grep -i -l yahoo.com

Notice here we're using "|" (to take the output of find, in this case,
just a list of filenames) to have the shell spawn the "grep" command,
instead of using "-exec" to have "find" run "grep" numerous times.

What xargs does is read from stdin (which in this case will be a list
of filenames :) ) and then take a considerable chunk of it (you can
specify how many with "-n max-args") and send it to the command you

In the above case, it will run simply this one command:

  $ grep -i -l yahoo.com ./foo.html ./bar.html ./baz.html ./index.html \
  ? ./links.html ./users/bill/index.html ./users/pete/search.html \
  ... etc.

This is useful if you don't like forking a gazillion times. :)

You can also use "locate" to pump filenames to xargs...

  locate .sh | xargs ls -l | cut -b 1-3,15-24,56-999

This will show all files with ".sh" in the filename (that 'locate' can show
you; ie, you can see them as whatever user you are, and they were in the
filesystem when "updatedb" was last run (typically, 4am today)).

Then I use "ls -l" to show some details about them, but rather than run
"ls -l" on each file (like you would with "find ... -exec ..."), we
use "xargs" to send a whole boatload of them to "ls".

Finally, for fun, I use "cut" to grab characters 1, 2, 3, 15-24, and 56-...
so we get the owner permissions, owner name, and filename of each file.

Fun fun!


LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.