|
|
|
|
UGU: Unix Guru Universe - Unix Tip #4281- November 30, 2012
- Home : Help
: Today's Tip
Unix Tip #4281- November 30, 2012
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)
|
|
|
Copyright 1994-2024 Unix Guru Universe |
|
|
|
|