Trash-cli : A Commandline Trashcan For Unix-like Systems
We all know that when we delete a file/folder, they will be moved to a temporary location called ‘Trash’ or ‘Recycle bin’. We can either delete the contents of Trash permanently or restore them if we need them later. This is how we use graphical Trashcans. However, If you’re a heavy command-line user and looking for a command-line alternative way to use Trashcan from the Terminal, you need to check ‘Trash-cli’ utility. Trash-cli is a command-line trashcan for Unix-like systems. It uses the same trashcan used by GNOME, KDE, and XFCE, but you use it from the Terminal. Using trash-cli, we can delete, restore items as the way we do in the graphical Trashcan.
In this brief tutorial, we will be discussing how to install and use ‘Trash-cli’ utility in Linux.
Trash-cli : A Command Line Recycle Bin For Unix-like Systems
Trash-cli is available on the default repositories of most Linux distributions.
To install it on Arch Linux and its derivatives:
$ sudo pacman -S trash-cli
On Debian, Ubuntu, Linux Mint:
$ sudo apt-get install trash-cli
On Fedora and other RPM based systems:
$ sudo dnf install trash-cli
$ sudo yum install trash-cli
If Trash-cli is not available on the repositories, you can compile and install it from sources.
To install it on system-wide, run the following commands one by one.
$ git clone https://github.com/andreafrancia/trash-cli.git
$ cd trash-cli
$ sudo python setup.py install
For user-level installation, run.
$ python setup.py install --user
Trash-cli supports the following functions:
- trash-put – Delete files and folders.
- trash-empty – Empty the trashcan.
- trash-list – List deleted files and folders.
- trash-restore – Restore a trashed file or folder.
- trash-rm – Remove individual files from the trashcan.
Allow me to show you some examples, so you can understand how it works!
To send a file named ‘file.txt’ to trashcan, run:
$ trash-put file1
Similarly, we can trash a directory using command:
$ trash-put dir1
You can verify it whether the files or folders have been sent to the trashcan in your file manager.
As you see in the above output, file1 and dir1 have been sent to Trash folder.
To view the contents of your Trashcan from Terminal, run:
Sample output would be:
2017-02-16 15:42:50 /home/sk/dir1 2017-02-16 15:41:47 /home/sk/file1
You can restore deleted items at any time using command:
It will ask you which file you’d like to restore. Just enter the number (0 or 1 in our case). The respective file will be restored. I wanted to restore dir1, so I entered 0(zero).
0 2017-02-16 15:42:50 /home/sk/dir1 1 2017-02-16 15:41:47 /home/sk/file1 What file to restore [0..1]: 0
now, the selected item will be restored.
To empty all items in the trashcan, you can use:
Also, you can remove a single folder/file from the Trashcan as shown below.
$ trash-rm file1
The above command will permanently delete the specified item i.e. file1.
Trash-cli also allows to remove contents older than x days. Say for example, to remove contents older than 7 days, run the following command:
$ trash-empty 7
You know now how to use trashcan from the commandline using trash-cli utility. Hope you find it useful. I will be soon here with another interesting article. Until then, stay tuned with OSTechNix.
Thanks for stopping by!
Help us to help you:
- Subscribe to our Email Newsletter : Sign Up Now
- Support OSTechNix : Donate Via PayPal
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Facebook | Twitter | Google Plus | LinkedIn | RSS feeds
Have a Good day!!