RSS

Deleting too many files

29 Feb

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.

Advertisements
 
Leave a comment

Posted by on February 29, 2008 in Uncategorized

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: