Sendmail

pudge on 2003-04-08T19:47:54

I just turned on Sendmail on my Mac OS X box that I use as a server. /var/spool/mqueue was empty, but I was getting hundreds of old cron emails. cfedde on #perl pointed me to clientmqueue, where I found 99,798 files. Oops.

killall sendmail and rm * ... argument list too long. perl -le 'opendir $x, "." or die $!; for (readdir $x) { unlink; print }'. There we go.


xargs is your friend

dlc on 2003-04-08T19:54:32

$ echo * | xargs rm

Re:xargs is your friend

pudge on 2003-04-08T19:58:14

Yeah, you probably use sed too! :)

Re:xargs is your friend

jmm on 2003-04-09T02:29:20

xargs is especially useful with find - it lets you run a command (like rm) on large numbers of files at a time, but breaking them up so it is not too many at a time. (Using -exec from find runs a separate command for each file found, which can be very slow for a large/deep file tree.)

Re:xargs is your friend

pudge on 2003-04-09T02:33:45

Yeah, I use xargs quite a bit, esp. with find ... however, I didn't think about using echo *. An ls took forever, I don't know how long echo * would take. readdir was surprisingly, relatively, fast.

Re:xargs is your friend

belg4mit on 2003-04-09T03:12:07

ls -1 is better than echo *,
because your shell still has
to do the globbing for the latter...
and you may lose

Re:xargs is your friend

pudge on 2003-04-09T03:20:22

That's sorta what I figured ... I don't know if the shell could have handled echo *. And again, ls took forever. Stoopid Unix!

Re:xargs is your friend

belg4mit on 2003-04-09T03:32:28

Doh! I missed that the first time through.
ls shouldn't be slow though. Stoopid MacBSD? :-P
Of course it depends on the filesystem,
it's not advisable for many to have single
directories with so many files. It might have
been quicker to remove the directory and
recreate it afterwards ;-)

Re:xargs is your friend

jmm on 2003-04-09T15:48:57

ls -f has been around since version 7 days, back when men were men and computers were slow. The -f option tells ls to use the order that it finds entries in the directory - which means that there is no time required to sort the entries before displaying them. With a really large number of entries in a directory, that sort could take a while (especially when Unix was running on a PDP-11).

Re:xargs is your friend

dlc on 2003-04-09T15:47:09

ls sorts the entries in the directory, while echo does not, which means ls will always be slower for large directories. echo * | xargs rm is simply the shell's glob operator, which is most likely implemented using readdir.

Re:xargs is your friend

jdavidb on 2003-04-09T13:51:18

My understanding is that only works for GNU xargs, though.

Of course, who would want to use a proprietary xargs?