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.
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
robert@acer:~$ ls /home/robert/.local/share/Trash expunged files info
~/.local/share/Trashdoes not exist by default. However, installing any file manager supporting FDO trash can specifications will add the
Trashdirectory. 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.
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
The package trash-cli adds the following rather intuitive commands:
Each of these commands has a
man page and I always recommended reading the
man pages, so try for example:
While there is no man page for
trash, it should be noted that
trash has the same action as
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.