1

I would like my trash emptied every 30 minutes.

I installed Autotrash, but it specified days of age.

Is there an alternative?

6

1 Answer 1

4

You can create a simple script file and set it up in cron to run every 30 minutes.

Create a new file with your script. You can put it anyplace. In this example, we will put the script in your home directory's ~/.config

sudo nano ~/.config/emptytrash30.sh

Add the following:

#!/bin/bash
find /home/yourname/.local/share/Trash/expunged/ -type f -exec rm {} \;
find /home/yourname/.local/share/Trash/files/ -type f -exec rm {} \;
find /home/yourname/.local/share/Trash/info/ -type f -exec rm {} \;

Save CTRL + O, and exit CTRL + X.

Make the script executable:

chmod +x ~/.config/emptytrash30.sh

Now set up cron to run the script every 30 minutes:

crontab -e

Choose an editor if you've never used cron before.

Add the following at the end:

*/30 * * * * /home/yourname/.config/emptytrash30.sh

This tells cron to execute your script every 30 minutes of every hour on every day, on every day of the week, on every day of the month.

Save CTRL + O, and exit CTRL + X.

2
  • I had to add this to the script. find /media/andy/MAXTOR_SDB2/.Trash-1000/files/ -type f -exec rm {} \; @Mirabeau
    – fixit7
    Aug 17, 2020 at 13:52
  • 1
    Yes you can of course add the "trash" of other HDs, as long as you understand the trick, no problem. Be careful, however, not to take the wrong path or make a typing error;) Remember to validate the answer if it meets your expectations: D
    – Mirabeau
    Aug 17, 2020 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.