Blog by Edo Frederix edofrederix@gmail.com RSS

Removing files on Linux: argument list too long

February 28, 2008

Abstract

Upon deleting a large set of files with the "rm" command in Linux, the error "argument list too long" often clog's up the process. How to solve this issue?

On the MyP2P website there is a (fairly simple) caching system which saves data to cache files on the disk. Sometimes, it is useful to perform a cache flush, by removing all the files. Normaly I would use the command "rm -fr ./*.cache" for that. But when there are a lot of cache files, this command throws the error "argument list too long".

This is because the "./*.cache" wildcard feeds all the files to the "rm -fr" command, resulting in a very large operation. To bypass this, we need to manually feed every filename to the "rm" program. The way to do this is:

find . -name '*.cache' | xargs rm -fr

Of course, you can substitude "*.cache" with whatever you like.