Machineware, Web Application Development
Web Application Development, Technical solutions, Consulting

How to remove lots of files in a directory (Linux)

SpamAssasin uses a directory to store messages that it thinks are spam. After awhile this directory will be full of thousands (depending on the traffic through your mail server) of files. When I tried to delete these files using the command rm * -f  I got the message:

too many arguments

 I was able to get around this error by using:

ls | xargs rm 

 The reason this works is because, well that's what xargs was designed to do (quoting from Linux in a Nutshell):

Execute command (with any initial arguments), but read remaining arguments from standard input instead of specifying them directly. xargs passes these arguments in several bundles to command, allowing command to process more arguments than it could normally handle at once. The arguments are typically a long list of filenames (generated by ls or find, for example) that get passed to xargs via a pipe.

 This has come in handy a few times.

Sep 14, 2007, 7:17 pm





Leave a comment

Name:
Name:
Email address (will not be published):
Email address (will not be published):
Comments:
Comments:
Website:
Website:



Subscribe to Machineware