trash: cannot trash regular file

I'm trying to avoid using rm so I don't delete anything permanently. I'm using the utility function trash, but it keeps telling me trash: cannot trash regular file. Why can't I delete these files? They are, for example, csv files I've created in a program.

$ ls -l | grep filename
-rw-rw-r--  1 username usergroup 298025 Sep 23 02:33 filename.csv

Running it with the -v flag gives:

trash: found unusable .Trash dir (should be a dir): /.Trash
trash: Failed to trash filename.csv in /.Trash/1005, because :[Errno 13] Permission denied: '/.Trash'
trash: Failed to trash filename.csv in /.Trash-1005, because :[Errno 13] Permission denied: '/.Trash-1005'
trash: cannot trash regular file `filename.csv'

I've noticed another feature too. I'm trying to trash the file from a directory that isn't mine. But if I mv the file to ~, I can trash it successfully there.


Solution 1:

GNOMEish file managers need a place to put the trashed files.

  • Deleted files on your "home" partition go to: /home/$USER/.local/share/Trash
  • Deleted files on other partitions can't be copied "home" for performance and space reasons.

So it tries to put them in the /[partition mount]/.Trash-$UID folder. Without rw access to that folder, no trash.

Run this bash in the partition root as the user who needs a trash.

sudo mkdir .Trash-$UID && sudo chown $USER:$USER .Trash-$UID

You can delete this folder and secure the partition / to disable that feature.

sudo rm -rf /[partition mount]/.Trash-xxxx
sodo chown root:root /[partition mount]/

Solution 2:

It looks like you're trying to trash a file from a directory where you don't have write access. You won't be able to do that. Look at the error you are getting:

trash: Failed to trash filename.csv in /.Trash/1005, because :[Errno 13] Permission denied: '/.Trash'

you either i) don't have permission to write to the directory containing the file (which you need to do in order to remove a file from it) and/or ii) don't have the right to write to ./.Trash since it's not your directory.