41

I know about the dangers of using root access so please forego the lectures. I try to be careful and will be doubly so from now on.

I was using the file browser with root access in order to change some file permissions. During the process I deleted some files (I should say that I out them in the trash). Little did I know that the files would go to the trash as root and now I can't remove them because I don't have the permission to read them but I don't know how to access them to change the permissions because I don't know how to get into the trash as root. All I get is a message saying that:

This location could not be displayed.

Sorry, could not display all the contents of trash:///: Operation not supported

I have searched around to try to find posts about it but I've only found outdated information about a hidden file in the root directory. That doesn't seem to apply any more so I'm stuck with a file in my trash that I can't remove and can't gain access to.

I'm using Ubuntu 14.04 64bit on an ASUS x401a laptop.

4
  • 1
    what about you relaunch nautilus as root and empty the trash ? Otherwise, you should be able to access your trash folder through terminal via sudo cd /home/your_username/.local/share/Trash
    – Aserre
    Aug 5, 2014 at 14:40
  • we do not use "solved" in titles here, instead, hit the green check mark on the answer that worked for you.
    – Mateo
    Aug 11, 2014 at 22:05
  • In this case the answer was in the comment from Ploutox. I can't seem to mark it. What can I do?
    – jeop
    Aug 14, 2014 at 13:26
  • @jeop when someone, especially someone with enough rep to know better, comments instead of answers, i paste it myself as an answer. you can always make it community wiki if you don't want the rep from it. see meta.askubuntu.com/questions/6706/convert-comment-as-answer
    – djeikyb
    Oct 10, 2014 at 5:51

6 Answers 6

32

You will need root access to the trash to be able to delete these files - the easiest way to do this in a temporary sense, is to open a terminal window alt+ctrl+t, and enter the command

gksudo nautilus /home/your_username/.local/share/Trash

This will execute the file manager with super-user permissions and you should be able to empty the trash from here. Delete the root-owned file.

When you are done, remember to close the program!

6
  • 1
    Thank you for your response but I've tried that and all I get is the message I stated above: "This location could not be displayed. Sorry, could not display all the contents of "trash:///": Operation not supported."
    – jeop
    Aug 11, 2014 at 21:56
  • K - then you might try using sudo as an interactive shell - type sudo -i, then start nautilus from the command line... Aug 12, 2014 at 1:43
  • Same error when running nautilus with sudo -i
    – andrsmllr
    Aug 14, 2020 at 13:56
  • @andrsmllr I believe gksudo was deprecated at some point in the past. Can you start a new question and more fully explain the situation that you are trying to resolve? Aug 14, 2020 at 16:05
  • @CharlesGreen Thanks for your effort. I resolved the issue using a root shell and removed the files manually from the trash (located at /root/.local/share/Trash/). Just wanted to leave a note that runnning nautilus as root did not work (for me).
    – andrsmllr
    Aug 15, 2020 at 18:44
20

If you would like to delete all of the contents of the trash you could use sudo and remove the entire directory. Remember to remake the directory so it doesn't cause any problems. The code is:

sudo rm -rf /home/User_Name/.local/share/Trash && mkdir /home/User_Name/.local/share/Trash

That will do it all with one entry into the terminal.

17

I personally use trash-cli a lot. I use it as an alternative to rm to be safe (e.g. trash -r my-folder).

sudo apt install trash-cli

Once installed you can do

sudo trash-empty
2
  • This solution worked perfectly. You can also use sudo trash-list to list the files deleted from the directory and sudo restore-trash to restore the deleted files back to the directory. Make sure to use the sudo command or the files added to the root thrash will not appear. Feb 1, 2020 at 18:15
  • trash-empty tries to empty user's trash and runs into the same problem. sudo trash-empty empties root's trash. There is no way to point trash-empty at a specific user's trash when running as root. Sep 17, 2020 at 12:43
6

run this in your cmd

sudo rm -rf ~/.local/share/Trash/*
2
  • 2
    You should explain, what this does exactly - and maybe change the command to not delete everything in trash.
    – guntbert
    Mar 7, 2015 at 12:56
  • The best answer. Worked perfectly.
    – Eje
    Apr 10, 2020 at 0:29
1

Use the terminal!1eleven (drag and drop)

  • Open a terminal with Ctrl+Alt+t.
  • To take ownership of the files again and continue in your filemanager, type the command sudo chown -R $USER:$USER and make sure there is a space at the end.
  • Now drag the the affected file or folder from your filemanager to the terminal.

    • The result should look like this:

      sudo chown -R $USER:$USER '/home/$USER/.local/share/Trash/files/some_file.txt'
      

      or this:

      sudo chown -R $USER:$USER '/media/$USER/path to external drive/.Trash-1000/files/sömё fïle thät may have fancy encodings, ſpaces & stu𝖋f.txt'
      

      where $USER stands for your user name in the path name.

  • Run the command by pressing Enter and probably refresh the view with F5 in the filemanager.

  • As noted by David Foerster, you can replace the apostrophes with quotation marks, to have shell variable expansion.

Using the terminal with files isn't that difficult when drag and drop works, is it? ^^ It is a very handy feature when you know how to use it.

Alternatively you can delete single files with rm. Deleting folders can be done with rmdir for empty folders or rm -r for deleting files and folders recursively. While the drag and drop method should work in almost all cases and properly escape everything you should still be careful when using deletion commands. Owning the files and deleting them in your filemanager is the safer solution.

Related

2
  • @DavidFoerster Your edit was generally right, but the apostrophes are automatically generated by dragging the file into the terminal. Replacing them in the examples will cause confusion.
    – LiveWireBT
    Mar 7, 2015 at 14:41
  • I'll suggest another edit, that explains the meaning of $USER then, because it won't appear like that on the terminal either. Mar 7, 2015 at 15:55
0

TL;DR: install trash-cli and execute:

sudo HOME=/home/<your-home-dir> trash-empty

Why are the other solutions wrong? They fall into two categories:

  1. Delete everything in the trash folder
  2. Run a command that actually does something different than the OP asked

Solutions of type 1 are wrong because the trash folder has structure that should not be modified directly. Whatever manages it keeps a small database there. If you delete that database, you risk breaking the trash functionality altogether. This may not be the case at this time, but may become the case at any point in the future.

The type 2 solution is sudo trash-empty, which empties root's trash instead of "your" trash. Without sudo, it would run into the original issue.

2
  • Use sudo -E to preserve the user's environment.
    – piegames
    Nov 8, 2020 at 13:08
  • <hour-home-dir>?
    – user598527
    Feb 7, 2021 at 7:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .