Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Free drive space by deleting miscellaneous excess files UNIX

I discovered that my Jaguar partition was slowly getting filled up by accumulated cruft that was not being dealt with by the periodic maintenance scripts (see the man periodic manual page for more info). For example, if you don't have sendmail enabled, any cron jobs that produce output or errors will write files to /var/spool/clientmqueue that never get used. I found about 100 MB of files there. Similarly, the cups system leaves files in /var/spool/cups. If you run HenWen (the snort network intrusion detection system), its log files accumulate in /var/log/snort -- up to a few megabytes' worth per day, depending on settings.

I use the following script to remove these extra, stale files. You can adjust the time limits in the find lines to suit your preferences.

#! /bin/sh
#  extended daily cleanup script
#  save as /etc/daily.local

## stale sendmail:
/usr/bin/find /var/spool/clientmqueue -mtime +7 -delete
## cups cruft:
/usr/bin/find /var/spool/cups -mtime +7 -delete
## snort stuff:
/usr/bin/find /var/log/snort -mtime +30 -delete
## BBEdit backups:
## Fill in the path to your backup directory below and uncomment the line
#/usr/bin/find [path to BBEdit backup] -mtime +365 -delete

I suggest creating the file wherever you like on your own account, then copy it:

sudo cp daily.local /etc
The sudo takes care of the permissions for the file and directory, plus you keep your own copy of the file in case the one in /etc gets zapped by a system upgrade or reinstall. I didn't put the script in /etc -> periodic -> daily because, according to the periodic man page, user-supplied scripts must return a precise exit status and that was overkill for what I needed to do.
  • Currently 2.75 / 5
  You rated: 4 / 5 (4 votes cast)

Free drive space by deleting miscellaneous excess files | 3 comments | Create New Account
Click here to return to the 'Free drive space by deleting miscellaneous excess files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Free drive space by deleting miscellaneous excess files
Authored by: cjmilne on Oct 31, '03 12:18:14PM

Of potential concern with this hint is if one of the directories is older then the mtime chosen, the directory will be deleted along with the files. Some programs won't handle this cleanly & may end up causing headaches. There's probably a find flag that can avoid this problem, or perhaps cd into the directory in question using the script then perform the find on the local directory :
cd /var/spool/clientmqueue
/usr/bin/find . -mtime +7 -delete
this works OK for me ('delete' has some restrictions on what it can & can't delete - it doesn't like paths with '/' & '.' in them) but you'd want to make SURE you were in the right directory.

[ Reply to This | # ]
Free drive space by deleting miscellaneous excess files
Authored by: LC on Jan 15, '04 10:00:53PM
To clean files, at least one should restrict find scope using -type f

[ Reply to This | # ]
Free drive space by deleting miscellaneous excess files
Authored by: tb on Apr 05, '05 10:23:48PM

If you are using IP printing, then be careful that you do not delete /var/spool/cups/tmp using this hint. Files are created in this subdirectory while printing, but if it is not present, tmp is not created when needed (at least with 10.2.8).

Use "-type f" as suggested.

[ Reply to This | # ]