Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

In order to reduce disk space usage, I want to automate a temporary clean in my Downloads folder. I figured two ways to do so:

1) Changing the configurations of firefox, etc. to save files to /tmp/ (this would require, for safety, changing the variable TMPTIME in /etc/default/rcS to 7 or more days);

2) Turning the ~/Downloads folder into a temporary directory that behaves similarly to /tmp/, deleting old files. The problem is that in /tmp files are indiscriminately deleted in the end of the session; in ~/Downloads folder it would be better to delete files by their creation date.

I'm not very sympathetic to the first option, since it requires a lot of config. I'd like some help to implement the second one. What's the best way to do it?

share|improve this question

1 Answer 1

up vote 17 down vote accepted

Instead of changing how the directory works, you could have a little clean-up script. It's easier to implement and probably less dangerous in the long run.

The following will delete anything over 7 days old in your ~/Download/ directory:

find ~/Download/ -mtime +7 -delete

You might want to test that by just removing the -delete segment and checking the files it returns. But once you're happy with it, you can schedule it to run once a day by running crontab -e and adding this on a new line:

@daily find ~/Download/ -mtime +7 -delete

ControlX then Y to save and exit and you're done.

share|improve this answer
4  
The tmpwatch or tmpreaper package are better approaches to cleaning up a directory, having been designed for exactly this purpose. –  MikeyB Dec 14 '11 at 18:41
    
+1 @MikeyB, but I would also put this in a script which runs at every boot, since a cronjob won't run if the machine is off when the job is due. –  scottl Jan 4 '12 at 7:41

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.