rm: Argument list too long - improved speed

Written by Peter Davies on .

Create a shell script containing:
ionice -c 3 find /home/<sitename>/public_html/var/session/ -name 'sess*' -mtime +3 -type f -delete

Replacing the "<sitename>" value with you own location. This will lower the priority of the command in the O/S and also use the "find" commands own delete mechanism which all-in-all is much faster than passing it to rm.

This can then be added to CRON using cron -e so that it executes on a regular basis:

# remove magento sessions
0 3 * * *  /bin/sh /home/<sitename>/session_cleanup.sh