18

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?

henrique
  • 467

2 Answers2

24

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.

Oli
  • 299,380
0

Assuming you have your trash setup to auto-expire after N days, I have also just symlinked ~/Downloads to my trash, eg:

mv ~/Downloads/* ~/.local/share/Trash/files/
rm -rf ~/Downloads
ln -sf ~/.local/share/Trash/files ~/Downloads

Then you don't have to reconfigure the download dir in any apps, eg. browsers.

Just check Gnome privacy settings to configure the auto-delete thresh:

set trash to expire after N days