e

How to use the Trash Can, cli style

The Bodhi Trash Can

Experience Level: Beginner and up

Prerequisites: None; “Using LXTerminal as Your File Manager” is useful but not essential

As previously noted deleting files with the rm command is rather dangerous because of the difficulty of recovering a mistakingly deleted file. Since we all make mistakes, modern operating systems have replaced the idea of a permanent deletion with the operation of simply moving a file to a temporary location, known as a Trash Can, and allowing a more permanent removal at a latter time. This gives the user time to be certain of the deletion and an opportunity to restore the file should the need arise. But how exactly is the Trash Can implemented in Bodhi Linux and how do we as command line junkies take advantage of this predominately GUI feature. These are the questions I wish to address here.

Trash Can Basics

In Bodhi Linux the Trash Can for each user is located at /home/username/.local/share/Trash where of course username is the users login ID. Exploration of this location reveals that files moved to the Trash Can are stored in the subdirectory files but data necessary to restore the file is stored in the subdirectory info.

robert@acer:~$ ls /home/robert/.local/share/Trash
expunged  files  info

With the release of Bodhi 2.1, the above information may not be correct. Bodhi 2.1 replaced the file manager PcManFm with Enlightenment's File Manager and EFM has no Trash Can support. Therefore, the directory ~/.local/share/Trash does not exist by default. However, installing any file manager supporting FDO trash can specifications will add the Trash directory. As will using the trash-cli commands discussed here.

The exact details of this implementation of a trash can are not really relevant here, but it should be noted that Bodhi Linux follows the FreeDesktop.org Trash Specification. Nonetheless, it should be apparent that moving a file, say sample.txt to the trash can is not as simple as a

mv sample.txt /home/username/.local/share/Trash/files/

command as one also has to create an info file telling the Operating System how to restore the file should the need arise.

Trash Can CLI

Since info files in the Trash directory are relatively simple, open one in vi, nano or leafpad and have a look, one might be tempted to write a simple script or program to implement this move to the trash can feature from a command line. Fortunately for us others have also thought about this problem and there are several such scripts available on the internet. So rather than reinvent the wheel I am going to suggest here the use of the trash-cli package, the program is relatively mature, functions well and avoids many of the problems a naively and hastily written script might run into.

While trash-cli is included in Ubuntu's repos and hence available in Bodhi I advise against using Synaptics or apt-get to install it. The version available in the repo is badly out of date and uses obsolete command line names. This guide, therefore, covers the use of the current version of trash-cli.

So first to the installation of trash-cli, I advise installing using the pip command as this allows one to easily uninstall the application should the need arise. Since pip is not installed by default, we have to install it:

sudo apt-get install python-setuptools
sudo easy_install pip

And now to install trash-cli:

sudo pip install trash-cli

should the need arise trash-cli can be easily uninstalled by:

sudo pip uninstall trash-cli

Trash Can Commands

The package trash-cli adds the following rather intuitive commands:

  • trash-put
  • trash-list
  • trash-restore 1)
  • trash-empty

Each of these commands has a man page and I always recommended reading the man pages, so try for example:

man trash-list

While there is no man page for trash, it should be noted that trash has the same action as trash-put.

Since the syntax of these commands is relatively obvious and both the man pages and the examples found on the packages home page should cover basic usage needs, I will leave it up to the reader to explore the commands on their own and forgo giving any further examples here.

It is my hope however that at least trash-put becomes part of your command line tool kit and that the reader uses it as opposed to the possibly dangerous command rm whenever possible.


User Feedback

how_to_use_the_trash_can_cli_style
Did you find this article helpful?
Yes, right on the money!
 
75%(15)
Somewhat. Needs work.
 
20%(4)
Not really
0%(0)
Not at all.
 
5%(1)

If you would like to comment or make further suggestions, please leave a note on our Comments page (you will have to Create an Account if you haven't already).

1) The Information on trash-restore on trash-cli's homepage is incorrect.
 
how_to_use_the_trash_can_cli_style.txt · Last modified: 2012/09/16 03:15 by rbtylee · [Old revisions]


© Copyright Bodhi Linux 2012. All Rights Reserved - Hosted by vaultnetworks