Ubuntu – I accidentally removed the Trash and can longer put items into it, how can I get it back

command linetrash

I did a stupid thing. I was having issues with certain files in my trash that my system was not allowing my to delete, meaning I could no longer empty my trash. These were not super important files, just theme folders I was creating and ditching. After getting frustrated, I googled it and was led to executing this script sudo rm -rf ~/.local/share/Trash/*which looks as though it totally removed my trash…completely and now I can no longer add items to it. How can I restore my trash once again? I know it's probably as simple as re-creating the file, but I'm unsure of the terminal language to do this.

Thanks in advance.

TL;DR I removed my trash directory with sudo rm -rf ~/.local/share/Trash/*and need help getting it back/making a new one.

Best Answer

Try:

cd ~
mkdir .local/share/Trash
mkdir .local/share/Trash/expunged
mkdir .local/share/Trash/files
mkdir .local/share/Trash/info
chmod -R 700 .local/share/Trash

... and then restart nautilus with nautilus -q. I am not sure it will work, it is just recreating the structure I have with an empty trash; you can safely ignore error about existing directory.

Notice, no sudo here. The trash is yours, should be manageable without superuser privileges; as a general rule, you should never use sudo to manage file in your home directory --- unless you have to fix previous sudo usage, that is.

If you have messed with superuser in this dirs, you may need to fix the ownership...

sudo chown -R myuser .local/share/Trash

Where myuser is your normal user, of course.

And BTW, the "not erasable file" was probably a file in another partition.