2

The .cache folder(The folder with cache) is eating up my space most of the time and I always how to clear it. How do I get Ubuntu to automatically delete every cache file, including clearing the recycle bin whenever it deletes it but only files that were in the cache folder not the ones deleted by me?

agamer569
  • 189
  • 3
  • 14

1 Answers1

0

WARNING: The .cache folder can contain data including browser history and preferences. Please see Is it okay to delete ~/.cache? for more information.

If you would still like to continue, the best way is to have a cron job that regularly empties the recycle bin and deletes .cache. Your computer may act weirdly until a reboot, so it is probably best to do this at boot time.

Create a script named clearcache.sh in /usr/local/bin. You may need root permissions. Replace yourusername with your username. Edit it with your favourite text editor and add the following content:

#!/bin/bash
rm -rf /home/yourusername/.cache /home/yourusername/.local/share/Trash
mkdir /home/yourusername/.cache /home/yourusername/.local/share/Trash

Run crontab -e and add the following line at the end of the file to run every 30 minutes:

*/30 * * * * /bin/bash /usr/local/bin/clearcache.sh >/dev/null 2>&1

Or this line for every boot:

@reboot /bin/bash /usr/local/bin/clearcache.sh >/dev/null 2>&1

Or you can use a different time in the crontab just as long as the command is /bin/bash /usr/local/bin/clearcache.sh >/dev/null 2>&1.

fosslinux
  • 3,831