Black God

How to manage Trash from command line in GNOME (delete, list, restore and empty)

Trash in GNOME is generally handled in Nautilus file browser. Trash icon’s context menu provides shortcut to empty trash. But while working in command line, you may not prefer to empty trash by going to Trash icon in panel or file browser.

In older version of GNOME, the trash folder is in .Trash folder in your home directory (~/.Trash). But in current version (2.30) it is ~/.local/share/Trash/. It has two sub folders called files and info. The files folder contains the files deleted and info directory consists of meta data for each deleted file.

Here is an example:

$ cat ~/.local/share/Trash/info/style.org.css.trashinfo
[Trash Info]
Path=/home/blackgod/Desktop/style.org.css
DeletionDate=2010-06-01T09:59:18

How to empty trash is straight forward now. Just delete the content of Trash folder – Check the below command snippet for more clarification.

$ rm -rf ~/.local/share/Trash/*

Warning: Be careful while using rm -rf command, so as not to delete other files.

Using trash-cli tool:

Install trash-cli tool, which manages the trash in command line which is equivalent to Trash functionalites in Nautilus fire browser. It acts upon the Trash directory we have mentioned above.

It can be installed with,

$ sudo apt-get install trash-cli

It installs three commands,

1. list-trash to list down the files in trash

2. trash to move the file to trash

3. restore-trash to restore the file to original path

The below console session is an example of its capability.

$ trash voice-message.wav

$ list-trash

2010-06-07 23:20:41 /home/blackgod/Downloads/voice-message.wav

$ trash ubuntu-10.04-desktop-i386.iso.torrent

$ restore-trash voice-message.wav
0 2010-06-07 23:22:21 /home/blackgod/Downloads/ubuntu-10.04-desktop-i386.iso.torrent
1 2010-06-07 23:20:41 /home/blackgod/Downloads/voice-message.wav
What file to restore [0..1]: 1

$ list-trash
2010-06-07 23:22:21 /home/blackgod/Downloads/ubuntu-10.04-desktop-i386.iso.torrent
Here are other tips to manage GNOME Trash from command line and shell scripts. It may be useful to you.

1. HOWTO: Automatically regulate the size and age of your Trash folder

2. How to limit Trash folder size using quota

I believe this post won’t go to trash, may be useful to some one :-)

7 comments for “How to manage Trash from command line in GNOME (delete, list, restore and empty)

  1. Updogliu
    November 14, 2011 at 11:41 am

    Well, it just works! THX a lot!

  2. July 15, 2010 at 3:19 am

    I really appreciate what you post here, very fresh and intelligent. One thing though, I’m running Firefox on Fedora and some of your content are a little off. I know it’s not a common setup, but it’s still something to to keep in mind. Just tossing you a heads up.

  3. July 15, 2010 at 3:18 am

    I really appreciate what you write about here. We try and read it every day so keep up the good writing!

  4. jarav
    June 8, 2010 at 5:06 pm

    In Arch linux, installing trash-cli, makes the following commands available:

    trash-empty trash-list trash-put trash-restore

Leave a Reply

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