Ubuntu – How to make Downloads folder behave like a temp directory

directoryhome-directorytmp

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?

Best Answer

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.

Related Question