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.

jeop
  • 411
  • 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 05 '14 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 '14 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 '14 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 http://meta.askubuntu.com/questions/6706/convert-comment-as-answer – djeikyb Oct 10 '14 at 05:51

6 Answers6

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!

Charles Green
  • 21,339
  • 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 '14 at 21:56
  • K - then you might try using sudo as an interactive shell - type sudo -i, then start nautilus from the command line... – Charles Green Aug 12 '14 at 01:43
  • Same error when running nautilus with sudo -i – andrsmllr Aug 14 '20 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? – Charles Green Aug 14 '20 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 '20 at 18:44
  • @andrsmllr This comment was written in 2014, and I had been using Linux for a year at that point. I would now vastly prefer to do exactly as you have done and use a shell to remove the files. Perhaps I should update the answer... – Charles Green Aug 17 '20 at 03:51
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
Prinzhorn
  • 561
  • 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. – HelloWorldPeace Feb 01 '20 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. – Szczepan Hołyszewski Sep 17 '20 at 12:43
6

run this in your cmd

sudo rm -rf ~/.local/share/Trash/*
David Foerster
  • 36,264
  • 56
  • 94
  • 147
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 & stuf.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

LiveWireBT
  • 28,763
  • @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 07 '15 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. – David Foerster Mar 07 '15 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.