Is there a way to limit the size of the Trash?

I just ran out of disk space and I have like 15GB in my trash. Is there a way to not keep items older than say 7 days or limit the size of the Trash?

I need a way to automatically keep this managed.


Solution 1:

The Trash is just a special folder (directory) that Apple creates and manages via the Finder so that you have some ability to easily "undelete" items (by removing them from the Trash) before you full-on delete (Empty Trash). Since this mechanism is just a directory on your startup disk, you technically have your entire startup disk's space to use up for Trash if you wanted to.

If you wanted some measure of "auto-magical" removal files older than 7 days, you can use a simple bash script:

find ~/.Trash -mtime +7 -exec /bin/rm -rf {} \;

Using your favorite text editor, paste the above line into a new file and then save the file as empty_trash_older_than_7_days.sh. In the terminal, be sure to use the chmod command to make it executable as such: chmod +x /path/to/empty_trash_older_than_7_days.sh

This command, when executed in the terminal, will find all the files in your Trash (files from your Startup volume only --more on this in a minute) that are older than 7 days (from the time you run this command) and pass each file to the rm -rf command. Since rm is a unix command and has no notion of the Trash, it just does a unix delete which for our purposes is real delete (like Emptying the Trash).

You could then use cron (if you are unfamiliar with Cron, check out the fine Cron entry on wikipedia) to setup a recurring execution of this script.

Personally, my vote is to just train yourself to use the Empty Trash menu item every few minutes, days, weeks?

P.S. if all this unix-ese is too frightening, I'd wager there are simple Mac Applications that people have written to do just this sort of thing. Hopefully someone with some knowledge of one ore more of these types of applications can offer up an answer or two as a counter balance.

Good luck!

P.S. I forgot to talk about the non-startup volume... If you delete a file from a volume OTHER than your startup volume, this file will go to the .Trash folder on that volume. For example, if you had a volume named Foo, there would be a .Trash folder at /Volumes/Foo/.Trash. What I have documented above will not delete those files. You'd have to setup something similar for each volume you have.

Solution 2:

Hazel can be configured to both keep files only for a certain amount of time and to keep the trash under a certain size. You could also add custom rules for deleting large files immediately or deleting files in the trash folders of other volumes.