Install trash-cli on Raspberry Pi

Install trash-cli on Raspberry Pi

On most systems with graphical environment, deleted files goes to a temporary location that is called Trash or Recycle Bin. Contents of the trash can be deleted permanently or restored. The trash-cli is a tool that allows to manage the trash via command line. This tool enables to put files to trash, restore files from trash or delete permanently.

This tutorial demonstrates how to install trash-cli on Raspberry Pi.

Install trash-cli

Connect to Raspberry Pi via SSH and run the following commands to update the package lists and install trash-cli:

sudo apt update
sudo apt install -y trash-cli

The trash-cli provides these commands:

No.CommandDescription
1.trash-put or trashMove files or directories to trash.
2.trash-listGet a list of files in trash.
3.trash-restoreRestore files from trash.
4.trash-rmRemove specific files from trash.
5.trash-emptyRemove all the files in trash.

We can check version of trash-cli as follows:

trash --version

Testing trash-cli

Create a new files and directory for testing:

touch file1.txt file2.txt
mkdir test
touch test/file3.txt

Move files to trash:

trash-put file1.txt file2.txt test

Now we can get a list of files in trash:

trash-list

Output:

2021-05-30 06:22:19 /home/pi/file2.txt
2021-05-30 06:22:19 /home/pi/test
2021-05-30 06:22:19 /home/pi/file1.txt

Trash directory is located at .local/share/Trash. This directory contains files and info subdirectories:

  • trash - is used to store trashed files.
  • info - is used to store information on where the files was located befere deletion.

We can restore files from trash as follows:

trash-restore

It will ask what files to restore. We need to enter the number:

   0 2021-05-30 06:22:19 /home/pi/file2.txt
   1 2021-05-30 06:22:19 /home/pi/test
   2 2021-05-30 06:22:19 /home/pi/file1.txt
What file to restore [0..2]: 2

We can remove specific file from trash using command:

trash-rm file2.txt

The following command removes all the files from trash:

trash-empty

Uninstall trash-cli

If trash-cli is no longer needed, we can completely remove it as follows:

sudo apt purge --autoremove -y trash-cli

We can also remove trash directory:

rm -rf .local/share/Trash

Leave a Comment

Cancel reply

Your email address will not be published.