House-keeping in Linux
Checked your /tmp folder lately? You might be surprised how many files there are if you do not clean it on a regular basis. To keep mine tidy, I have a small script called ‘cleantmp’:
#!/bin/bash
find /tmp -atime +5 -exec rm -r {} \;
find /var/tmp -type f -atime +30 -exec rm {} \;
Basically it looks for files in /tmp that are at least five days old and removes them, including subdirectories.
In /var/tmp it allows the files to stay a bit longer: 30 days.
To keep your system clean as well, save this script in /usr/local/bin as ‘cleantmp’ (or any name you prefer), and make it executable with:
chmod +x /usr/local/bin/cleantmp
Now if your system stays on 24 hours a day, you can schedule this script from crontab:
ln -s /usr/local/bin/cleantmp /etc/cron.daily/cleantmp
But if you normally turn of your computer, you can call ‘cleantmp’ from /etc/rc.d/rc.local
Happy Slacking!
This entry was posted on Saturday, September 27th, 2008 at 20:04 and is filed under Linux, Maintenance. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Dutch guy living in Brazil. Has worked in the IT business since it was invented (well, almost...). Interests: Slackware, Lego, Star Wars.
Leave a Reply
XHTML: You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>It may take some time for your comment to appear, it is not necessary to submit it again.