3

I have tried to find my trashcan in order to free some space on the disc. I have tried the suggested commands How can I empty the trash using terminal? but it seems like I don't have any local folder. I have tried to list all hidden folders aswell, without finding any local or trash folder. Are removed files stored somewhere else or how to restore space from the delete files if no trashcan found?

I'm using the terminal.

  • What do you mean exactly by "using the terminal"? is this a desktop or a server installation? 'trash' is a GUI/desktop concept – steeldriver Aug 23 '16 at 12:05
  • It's server installation, not done by me. If there is no trash in terminal mode, there must be something simular? How to gain access to discspace previous occupied by deleted files? – Lars Ljungberg Aug 23 '16 at 12:29
  • 1
4

Pre-Author's Note:

Read through all of this post until you find a satisfactory solution. If not, add a comment telling me I am the worst wannabe in the world. ;) Also, the Trash is not what is taking up all of your space. You do not have a Trash Can created, below are instructions of how to make one. In the terminal, when you delete something it is gone forever, except if you use a recovery program like foremost (see below.)

The Location of the Trash Folder

The trash folder is located at /home/username/.local/share/Trash/. This folder may not be there because of you running from terminal, but keep reading! It is only created once a file has been moved there with a GUI (I'm not 100% about this part, but my LXDE setup only created it when I moved a file to there with the file manager).

Explanation:

Due to @Zacharee1, I have realized the true nature of your question. Thank you for that @Zacharee1. So, a Trash Folder doesn't exist in terminal-land, so you have to either create your own or be OK with having the danger of losing important files forever. Of course, that means that the space usage is not caused by that.

If you have a Trash Folder Already Created:

The items inside the Trash folder will be inside another folder, the items folder. Now, if you want to clear this use two separate commands.

rm /home/username/.local/share/Trash/items/*
rm /home/username/.local/share/Trash/info/*

If You Just Want To Restore Some Files:

Take a look into the forensics program foremost. You can download with

sudo apt-get install foremost

Look at online instructions for using it, use the man page or look below at my extremely limited understanding of how this works. Let me stress that, I just found this and am not knowledgeable in this area, so do not think everything I say is true. On HowToForge (https://www.howtoforge.com/recover-deleted-files-with-foremost) it tells you to run

foremost -t filetype -i /dev/sda1

(Obviously) Replace filetype with the type of file you need to recover. For example, if I wanted to recover pdfs I would do

foremost -t pdf -i /dev/sda1

You will find what is recovered in a folder in the directory you are in called output. If you want to do it multiple times in the same directory, do

foremost -t filetype -T -i /dev/sda1

The extra -T stands for timestamp so the separate outputs won't mess eachother up. For a better understanding of foremost, check out the link provided or do your own research.enter code here

If You Don't Have a Trash Folder Created (And You Want One):

This one is probably you! So, you might have to try two separate things.

The first, and probably most unappealing, is to figuratively make your own Trash folder, set up a timer for it and a system for the files inside to be deleted. You can do this by adding a script to your crontab, which has a timer of 1 month. When the timer gets high enough, BAM,

rm /path/to/trash/*

If you Don't Want to Do It Yourself:

Alright soldier! There are a couple of things you need to know. The crontab. A useful tool which lets you run scripts and commands at startup. We probably will be using this. There is a big flaw to the idea that I just proposed. The timer will it only run if your computer is on. AHA, I've got a (slightly) better idea!

The Slightly Better Idea!

Alright, this will involve a python script and a .txt! Hurray! You will need an empty txt file in the same folder as this one called garbage.txt. So, basically, these are the contents:

#!/usr/bin/env python3
#Comment: This Will Be Called Trash.py

import datetime
import subprocess

with open("garbage.txt", "r+") as garbage:
     x = int(garbage.read(1))
     now = datetime.datetime.now()
     month = now.month
     if month != x:
         subprocess.Popen(['rm', '-rf', '/where/ever/trash/folder/is/)
         subprocess.Popen(['mkdir', '/where/ever/trash/folder/is/'])
         with open("garbage.txt", 'w+') as sadness:
         sadness.write(str(month))

Now then, add this script to the crontab. I'll assume for benefits of the reader that you don't know how to do this. So, create a bash script in the same directory as trash.py. Call it trashshell.sh. In it write:

#!/bin/bash
python3 trash.py

Save that, then type in the command crontab -e to the terminal. Select the terminal editor nano and then write

@reboot sh /path/to/trashshell.sh

Hope this helped!

Optional: An Easy Delete!

Put this:

function trasher(){
     mv "$1" /path/to/trash
}

into your .profile or your .bashrc (Do bashrc if it exists). This will all you to move items to trash with trasher itemname. For example, trasher new.txt

A probably False Idea!

Try recreating a Trash folder in the spots it would be, like the Trash folder, the expunged folder, the files folder, and the info folder. Wait 30 days. This probably won't work!!!

Author's Note:

Do not copy and paste the code I wrote. The indentation is almost 100% messed up, because cannot do formatting on Stack Overflow! Some one teach me please!!! If you made your own trash folder and you're feeling adventurous you can change some stuff up a bit, like the length of the timer.

  • I think I have fixed your code indentation. – edwinksl Aug 23 '16 at 13:56
  • I fixed the python code, added crontab explanation – James Bond Aug 23 '16 at 14:25
5

From what I've seen, Trash is just an indexing feature. When a file is deleted from the file manager, it's moved to ~/.local/share/Trash/, which it's directory structure kept intact. (EG: if you delete ~/testfolder/testfile.sh, testfile.sh will go to ~/.local/share/Trash/testfolder/testfile.sh.)

(If you use sudo or gksudo to open a file manager, /root/.local/share/Trash is the trash directory used for that session.)

Unfortunately, that's a GUI thing. The terminal doesn't do that. rm actually deletes the file; it doesn't just move it to a trash folder to later be recovered or deleted, it skips the trash completely. If course, you can recover files, but only if you haven't overwritten the space on the hard drive they used to occupy.

You have to be much more careful in the terminal, since it's not exactly designed for ease of use and convenience. Since there's no trash, deleting files is more dangerous. Also since there's no trash, there's no trash to delete to save space. Something else is filling up your hard drive.

  • 1
    @LarsLjungberg if this answered your question, you should accept it :) – Zanna Aug 23 '16 at 14:01
2

Open nautilus or whatever filemanager you use and type in the addressbar (ctrl+l)

trash:///

Then you should be in your trashcan.

I compared the content of my trash from nemo (my filemananger in Linux Mint) with the content of the output of ll -R ~/.local/share/trash. And it looks like what I see in the filemanger is located in the subfolder info.

From the terminal:

rm -rf ~/.local/share/Trash/info

But as you said, you don't have any Trash. That's odd unless you removed your files from the terminal. If you did that, the files are really deleted and not moved to the trash!

No ~/.local/ in a server installation after a fresh installation

  • I forgot to mention that I'm running from the terminal – Lars Ljungberg Aug 23 '16 at 10:30
  • I updated my answer. I hope it helps you in any way. – Kev Inski Aug 24 '16 at 7:20
  • I wonder if you did install just the server version of Ubuntu without any GUI?! I will check if there is a trash folder in this version. It tankes some time because I have to download and install it in a VM. – Kev Inski Aug 24 '16 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.