How to manage the trash from the terminal

How to manage the trash from the terminal

In the following article I will show you how to manage the recycle bin from the terminal of our operating system Ubuntu.

Surely you are thinking that what is this for, since we can do everything from the Graphic interface of our system, and I have to tell you that it is indeed much easier to do it graphically, but I must also tell you that it is never too much to know how the terminal works, and what we are actually doing when we move, delete or restore a file or directory from the recycle bin.

First of all, it will be to open a new terminal:

How to manage the trash from the terminal

Now we have to know which route it is on the recycle bin of our operating system, and in this case, Ubuntu, we can find it in the route:

.local / share / Trash / files

So to access from the terminal we will have to write:

cd ~ / .local / share / Trash / files

How to manage the trash from the terminal

Now for list or view content that we have in the trash we will use the ls command:

ls

How to manage the trash from the terminal

As we can see in the screenshot above, I only have three files created especially for this tutorial, so we can see a folder called binder, a document called document and another document called Untitled document.

How to delete a document, file or directory

For remove completely a file or document we will use the command rm, for example, to delete the document we will write in the terminal:

rm document

If we wanted delete folder, we would have to write rm - r:

rm -r Folder

How to manage the trash from the terminal

Restore items

To restore the elements that we want from the trash we will do it in two ways, or moving them to another directory or copying them.

With the command mv We will move them to where we want:

mv document / home / francisco / Documents

How to manage the trash from the terminal

With this line we will move the document to our directory of the personal folder Documents, logically we will have to change the username for our user.

For copy we will do the same but using the command cp:

cp document / home / francisco / Documents

How to manage the trash from the terminal

Finally, para empty completely the recycle bin, wherever we are, that is, without being directly on the route /.local/share/Trash/files, we will type the following line in the terminal:

rm -r /home/francisco/.local/share/Trash/files/*

How to manage the trash from the terminal

Notice that at the end of the line there is an asterisk* and what should we change Francisco by your username.

This is the only command that we can execute from any part of the terminal, the others will have to be positioned in the path specified above which is where the Ubuntu recycle bin is located.

More information - Getting into the terminal: basic commands


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Quixotevirtual said

    Thank you very much, I am starting in linux and the truth is that I am very interested in the operation of the terminal ... your input was very useful and I will be aware of your publications.
    Ferdinand (Argentina)

    1.    Francisco Ruiz said

      Thank you very much friend, we will be publishing entries about the terminal and basic Linux things.

  2.   guest said

    An alternative is to install the package "trash-cli" and take advantage of the commands that this package brings trash-empty, trash-list, trash-put, trash-restore

  3.   JAUP said

    Hello, what happens is that I accidentally delete an entire folder and it contains many files, I would like to ask how I can recover them without writing the name of each one, as shown in the example, since there are too many files. Thanks

  4.   King said

    Your article is interesting, but it happens that I do have a serious problem with my recycle bin for a few days. Turns out, for some reason, I found it appropriate to use the BleachBit and ran it. Then one thing happened, my lap froze and didn't come back, so I restarted it again. But, in my personal folder, this rsABwlUlf file appeared, I have no idea where it came from, so I deleted it and when I wanted to empty my recycle bin, my whole laptop becomes dull and serious, neither the famous rsABwlUlf nor the other garbage. I would like you to help me, I use linuxmint 17, Rebecca, this last one I got (Rebecca) when updating Qianna 17. Thanks.

  5.   Jean Zion said

    Thanks for your good support, it actually worked! although it is not clear to me yet why the folder that I could not delete from graphical mode acquired write protection. Of course I had to enter as "sudo su" before entering "cd ~ / .local / share / Trash / files", there I applied "rm -r *", that eliminated everything. Thanks again, Greetings!

  6.   esther bogadi said

    good excuse me, see, the address I mean the primary operation key to access the trash does not work for me, it says "there is no file or directory", which I put wrong? Is it because my linux is not so advanced?

  7.   Mario said

    I have the same problem as Roi with the difference in the name of the folder which in my case is CfZ6_zIbVu and I can't delete anything that I have in the folder either normally or with sudo su.
    You may be able to help me.
    Thank you

  8.   Mario said

    I have the same problem as Roi with the difference in the name of the folder which in my case is CfZ6_zIbVu and I can't delete anything that I have in the folder either normally or with sudo su.
    I use Ubhuntu 14.04
    You may be able to help me.
    Thank you