RSS

Monthly Archives: February 2008

Deleting too many files

When you try to delete a big number of files in a directory of thousands using:

rm *

You’ll get an error. Linux complains about “Argument list too long”. Issue this command from a directory where files are located to get rid of them:

find . -exec rm {} \;

If you want to delete a large number of cache files, without deleting them all, the best way is to delete the files that were not recently accessed. Say you want to keep the popular cache hits which were accessed in the last 5 days and remove older files, your command would be:

find . -atime +5 -exec rm {} \;

If you try to use a wildcard when using find, you’ll be limited to the maximum number of pages your argument list can accept, which is a kernel limit. So, to work around this, I created a subdirectory for each cache group so I can use a directory name as the first parameter of find. The following example deletes items from cache which were not accessed in more than 4 days. This Something like this:

find /www/site/ci/system/cache/khcache/ -atime +4 -exec rm {} \;

Previously, I was using a wildcarded ‘find’ which was failing:

find /www/site/ci/system/cache/khcache_* -atime +4 -exec rm {} \;

Don’t forget to fix your cache directory setting in your configuration files.

 
Leave a comment

Posted by on February 29, 2008 in Uncategorized