2

According to How is the /tmp directory cleaned up?, the /tmp directory is cleaned up using tmpreaper, which uses cron to schedule cleanups at fixed time intervals. However, I would instead like to enforce a certain maximum size of the tmp directory. Is this possible?

Kurt Peek
  • 409

1 Answers1

1

You could write a little script:

#
#      your maximum size of /tmp in kbytes
#
maxsize=1000
#
#      now get the actual size of /tmp in kbytes
#
tmpsize=$(du -ks /tmp|cut -f 1)
#
#      when maximum reached, clean up
#
if [ $tmpsize -ge $maxsize ]; then
    rm -r /tmp/*
fi

This should be run as root, in order to clean up files owned by other users (including root) as well.

derHugo
  • 3,376
  • 5
  • 34
  • 52
Jos
  • 30,529
  • 8
  • 89
  • 96