Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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.

share|improve this answer
1  
OS X's find also has a -delete flag so you could use find ~/.Trash -mtime +7 -delete. The modification dates aren't a very good indication of when files were deleted. I don't know any way to access the date deleted metadata shown in Finder though. –  ؘؘؘ Aug 1 '12 at 15:24
    
Agree with the comment above... Although this is a nice script, in practise it deletes stuff by its modified date. Therefore, if I trash a folder of old stuff now and then run the script straight after, most of the stuff from that folder is deleted. Would be good if we could find a parameter for the date deleted on the file. –  Jowie Nov 8 '12 at 9:11
    
@Jowie we can use -atime which is last access time. By the way there's another problem — this leaves empty directories in Trash... –  Sarge Borsch Jul 1 at 22:45

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.