Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I use the OS X at command to schedule a daily clean-up of the user's .Trash folder?

I'm thinking something along the lines of:

rm -rf ~/.Trash/**/* | at 0:00 + 1 day

Will this clean the trash every day?

We'll be running this command as part of a login script, so I also need a way to clear all the scheduled tasks. Is there a way to at -r all?

share|improve this question
Is there any particular reason you want to use at vs cron/launchd? AT might not be better for this type of activity. – Eric G Feb 25 '13 at 3:34
Just so we can schedule it easily via a login script that runs every time the computer loads. Can we do this via cron? – Chris Nolet Feb 25 '13 at 3:37
The following question may be useful, if not, please let us know:… – Eric G Feb 25 '13 at 3:38
Yep, saw that. Not sure how to flush the jobs though. Do they flush on reset? Likewise, I've seen different syntax in different places - just wondering what the latest one is. – Chris Nolet Feb 25 '13 at 3:43
up vote 1 down vote accepted

rm -rf ~/Trash/* often results in permission denied errors unless you run it as root. osascript -e 'tell app "Finder" to empty trash' would also show an error dialog if some files are in use.

You could try adding 0 0 * * * rm -rf ~/Trash/* to the root's crontab (sudo crontab -e).

Or using launchd, save a property list like this as /Library/LaunchAgents/empty_trash.plist (and make it owned by root):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN>
<plist version="1.0">
        <string>/Users/username/Trash/*</string> <!-- ~/ doesn't work -->

It's loaded automatically on the next login, but you can load it immediately with sudo launchctl load /Library/LaunchAgents/empty_trash.plist.

Hazel also has options for emptying the trash automatically.

share|improve this answer
Great - thanks! Just what I was looking for! – Chris Nolet Feb 25 '13 at 10:19

Your Answer


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.