How to turn off the trash bin functionality on individual drives?

Hi!

In my system I mount a couple of external disk drives and , more important, CIFS network drives. Also my local system hosts 5 drives with different sizes.

How can I turn off the trash bin completely for these drives?

Most are hosted on a NAS - there is a different trash bin in place already, also other users with Windows system access the drive - creating even more trash bins folders and systems…

Now in Dolphin I can restrict the size of the trash bins on different drives but this is not very comfortable. Setting the trash bin on a huge NAS drive to the lowest setting still creates a trash bin and it is quite large still.

Now first of all it would be really nice to be able to set also the trash size to an absolute number like 1 GB - the fiddling with percentages is not very intuitive, as sizes on different drives vary immensely (e.g. SSD drive 250 GB next to a NAS network drive of 19 TB…).

But here is my main question:

How can I turn of the trash bin on individual drives?

It’s impossible to simply set the size to 0% via the GUI nor to turn it off?
Is there a config file setting?

I know that I can bypass the trash bin when deleting individual files. But that’s just a workaround - I do not want any trash bin folders on my network drives.

In my opinion there should be a setting in the properties for each drive (maybe even each folder) to switch off trash (and also toggle indexing on or off btw - as it is also unintuitively hidden away in settings…).

I’d really appreciate some help with this.

Thanks for reading,
jhhh

1 Like

Making the Trash Dirty

First step, empty trash:

sudo rm -vdrRR ~/.local/share/Trash/*

That done, let’s mess with the immutable bit:

sudo chattr +i ~/.local/share/Trash/

So now you should see:

Cannot move to trash, delete it immediately?

do to an error: chattr: Inappropriate ioctl for device while reading flags on ~/.local/share/Trash/

This only applies to GUI deletes, right? Because rm does just remove stuff.

If you don’t like that, then try another tack:

sudo chown -R root:root ~/.local/share/Trash

Then you get a different message:

Cannot move file to the bin, do you want to delete it immediately?

@daily $HOME/bin/clean_trash.sh

However, you can make the trash a lot more temporary (perhaps this way allow a few minutes for blunders to be recovered) and strikes me as a tad more elegant:

cat ~/bin/empty-trash.sh
#!/bin/sh

# https://github.com/andreafrancia/trash-cli
trash-empty 7

You could bang this in as a systemd service :wink:

Mess with the $PATH:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ]; then
  PATH="$HOME/bin:$PATH"
fi

You could set up ‘trash-empty’ to run (from trash-cli) at startup too.

Thank you for your detailed tipps!

But for clarification:

This doesn’t turn off trash only on the external and network drives, right?
Wouldn’t it just turn off trash globally?

Maybe I haven’t explained myself very well… - I like and use the trash functionality!

I just want to switch off the trash bin on some individual drives - either completely or at least by setting the trash bin capacity to 0% or zero bytes.

The latter would still create those trash folder trees, so switching off trash bins completely on the chosen drives would be the better solution.

I use KDE since KDE 4 and this has always created problems for my use case. The inability to just decide to have a working trash bin on some partitons but not on others drives me nuts…

I want to use a trash bin on

  • my root drive,
  • my home drive,
  • my drive for media storage

but not on

  • my NOCOW partiton for databases
  • my mounted network drives
  • any backup media
  • and certainly not on external disks and thumb drives

I’ve always worked around this. But also there have always been lots of problems. (Trash bins changing permissions on shared drives, duplicated trash bins created by different systems, some un-deletable files, even file corruption - the list goes on and on…)

Every time I help out fixing problems on any windows system, I am baffled how simple this can be - just by just toggling off “Use trash bin on this drive”.

Can’t the systemd service be targeted at different mounts?

Thanks for your help!

Cheers, jhhh

Hmmm not sure - how about:

trash-rm \*.o

Working out how to include and exclude paths from the expression.

Hmmm… just for me being slow to understand the situation:

Am I right in the assumption that there is no intended way to do this at all?

It seems hard to believe for me that I am the first user struggling with this?

Don’t get me wrong - I really appreciate that you are thinking about it!

It’s just that I assume there would be a way to do this somewhere that may not be as well documented as other things about KDE?

Cheers, mate!

Hi - for what it’s worth, there is an existing feature request in the KDE Bugtracking System for the ability to disable Trash bins, and that mentions per-disk configuration: 148450 – option for completely disabling Trash mechanism

I had the same issue with trying to disable the trash bin on network drives and it was a bit of a pain. What worked for me was editing the trashrc file in ~/.config/ or ~/.kde/share/config/. In there, you can set trash_disable=true for the drives you don’t want to use the trash on. It stops the trash bin from being created at all, so no need to mess with size settings anymore. Just keep in mind, once you do this, files are permanently deleted, so I’d be cautious about deleting things you might want to recover.

1 Like