[SunHELP] xargs ?

Robert Banniza sunhelp at sunhelp.org
Tue Jan 8 08:22:44 CST 2002


Wyatt,
Just an FYI for killing process, there is another way that involved
less typing. The command is called pkill and can be found on Solaris and
Linux. There is also a pgrep command. Just another example that their is
more than one way to do it in UNIX. ;-)

Robert

Robert Banniza
Senior UNIX Administrator
Ascension Health
Phone: 812-228-2157

>>> wyatt at draggoo.com 01/07/02 10:50PM >>>
Heh.  xargs is one of my favorite commands --- and one very often
overlooked, from what I've seen.

xargs effectively runs a command for each thing passed to it from a
pipe.  For instance:
$ find / -name core | xargs rm
will remove all of your core files (barring permissions, etc.  And I
know that `find / -name core -exec rm {} \;' is cleaner, but this served
as an example...)

One of the best uses I've found for xargs is for killing processes:
# ps -ef | grep baduser | awk '{print $2}' | xargs kill -TERM
This will kill (nicely) all of baduser's processes.  In scripting, I'd
probably sleep for a couple of seconds, and do the same with -KILL
instead of -TERM to make sure I've gotten the stubborn ones.

Wyatt

> 
> Dear guru
> Someone please distinguish me about the following things:
>  Pipe '|'
>  Redirect '>'
>  xargs
> 
> I understand '|' and '>' but not 'xargs'. Please give me a guide
line
> when I should use 'xargs'? how difference between 2 above
> or point me to some source of information about this.
> 
> Thanks in advance
> Patrick.
> _______________________________________________
> SunHELP maillist  -  SunHELP at sunhelp.org 
> http://www.sunhelp.org/mailman/listinfo/sunhelp 
_______________________________________________
SunHELP maillist  -  SunHELP at sunhelp.org 
http://www.sunhelp.org/mailman/listinfo/sunhelp


NOTE: This e-mail message may contain information that may be privileged, 
confidential, and exempt from disclosure.  It is intended for use only by 
the person to whom it is addressed. If you have received this message in 
error, please do not forward or use this information in any way, delete it 
immediately, and contact the sender as soon as possible by the reply option
or by telephone at the telephone number listed (if available).  Thank you.



More information about the SunHELP mailing list