Whilst being an excellent ecommerce platform, Magento isn’t the tidiest of beasts and likes to leave session data lying around at its arse.
Session files are tiny so you could be forgiven for ignoring them most of the time, but the issue is there is a lot of them and Magento doesn’t have a built in method for dealing with them.
Because they are so small but there is so much of them I have actually found times when a linux box has ran out of space but reports that there is still some space left, this I think is because the processes that calculate filesizes are falling over the sheer amount of session files left by Magento.
Anyone familiar with the command line will scoff and point out that a simple rm -rf var/session/* will do the job, and you are almost right, but because there are so many of these files normally what will happen is this command will attempt to run and then return an error about too many arguments.
To get around this you need to run something like;
find /path/to/magento/sessions/ -name "sess*" -type f -delete
I wont get into the details of each aspect of this line, other people have covered this in way more depth – but basically this will run the rm on each single file and not try and pass in all the files at once.
This will clear out your sessions folder and free up some space.
If you don’t want to clear out all session files, maybe just older ones, you can add the -mtime parameter to this line.
Update – I have changed the delete line to use -delete instead of -exec rm -rf {} \;