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?
Asked
Active
Viewed 162 times
1 Answers
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.
find /tmp -mtime +x -delete
. Seeman find
for more options. Of course, if there is a risk of deleting valuable data, you shouldn't run this script at all. – Jos May 29 '17 at 11:44