Unix Tip #4281- November 30, 2012


SEARCH : Home : Help : Today's Tip

POWER OF XARGS


Don't over look the power of xargs. By default
in some flavors of unix, the command line is
limited to roughly 20K bytes.

Some directory lists can well exceed that.

Secondly, performance using

% find /tmp -name foo -exec rm \;

will fork the rm command for every file it
finds. If this were to return 1000s of files
you get rm forked 1000s of times.

But,

% find /tmp -name foo |xargs rm

while getting the same effect, rm is forked
with a long list of files, and thus system
overhead is reduced, and the command runs
faster, and system impact is reduced.

This is also important if you have list of
files produced by

% find {blah} > listfile

Once you edit your list to remove those
files you really want to keep, then

% cat listfile| xargs rm

Will remove all the files in the file. While
% rm $(cat listfile) will

Fail if listfile is greater than ~20K



NOTE: All tips provided are USE AT YOUR OWN RISK. Tips are submitted by various unix admins around the globe. UGU suggest you read and test each tip in a non-volitile environment before placing into production.


LAST 5 TIPS
4280 - BACKUP CRON JOBS
4279 - DIFF HUMAN READABLE
4278 - 7 DAYS AGO
4277 - VARIABLE USAGE i or ii
4276 - SOLARIS 9/10: IP FROM IFCONFIG


I want to SUBSCRIBE and get a UGU Tip everyday.
I want to UNSUBSCRIBE and NOT get a UGU Tip everyday.

If you have a UNIX TIP let us know, we just may use it:
(All tips become the property of the Unix Guru Universe)
Email Address:

Yes, email me a Hot Unix Tip everday.

Enter Hot Unix Tip (optional):

Yes, I will support this tip

Captcha (not case sensitive):


Please enter the above letters:


HOME | Flavors | Admin | Network | Security | S/W | Help | Events | Vendors | Careers | Internet
About | Add Link | Feedback | Search

Copyright © 1994-2005 Unix Guru Universe