Monday, February 2, 2009

Cleaning out /var/virusmails

bin/rm: Argument list too long

Ever seen that before? I ran into it while trying to clean out /var/virusmails on a Tiger Server system. It had about 230,000 items in it. The solution? find and xargs.

find /var/virusmails/ -name 'spam*' -print0 | xargs -0 rm -f

This will remove any file in /var/virusmails whose name starts with "spam". Of course, if you just want to remove any file in there (like those virus and banned ones), regardless of name, you would instead use

find /var/virusmails/ -type f

which will just return anything that is a regular file. find has a lot of very interesting options. I highly recommend that you check out the manpage for it. And for xargs, while you're at it.

Something to note: putting sudo before the command will sudo the find, but not the rm. Better to run the whole thing as root. Just be careful. Avoid tyops.

No comments:

Post a Comment