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.
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:
|1.||Move files or directories to trash.|
|2.||Get a list of files in trash.|
|3.||Restore files from trash.|
|4.||Remove specific files from trash.|
|5.||Remove all the files in trash.|
We can check version of trash-cli as follows:
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:
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
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:
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:
The following command removes all the files from trash:
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