Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

rm Argument list too long.. Linux Huh? moment.

I recently had a little problem when deleting a store of spam e-mails off one of my personal servers.

Basically entering the standard death defying command of “rm -Rfv *” while in a directory (this will delete everything recursively – have fun), the system responded “Argument list too long” – cue the first “huh?” moment – I’ve used the command for years and years, never had a problem.

I did “man rm” to check I hadn’t had a “moment” and forgotten how to use it – nope.. . A little trawling came up with several people with the same problem but no really practical solutions.  The problem occurs when you have too many files for the built in systems used by the rm command in the kernel – these are pretty old so have some limits that you don’t expect! – you can do this:

rm -Rfv a* then rm -Rfv A* –  these deletes all files starting with a or A etc.. – very long and rather silly – so after thinking and thinking and muttering an old command came to mind 🙂  using a combination of find and xargs you can pipe a file on at a time so here we go – my favoured solution:

find . -name * | xargs rm -fv

This works fine – I suspect it will have a limit somewhere, but my server hasn’t hit it yet!

%d bloggers like this: