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 command line tool for managing the trash. It enables to move files to the trash, restore them or delete them permanently.
This tutorial shows how to install trash-cli on Ubuntu 24.04.
Install trash-cli
Run the following command to update the package lists:
sudo apt update
Install the trash-cli:
sudo apt install -y trash-cli
The trash-cli provides several commands for managing the trash:
No. | Command | Description |
---|---|---|
1. | trash-put or trash | Move files or directories to trash. |
2. | trash-list | Get a list of files in trash. |
3. | trash-restore | Restore files from trash. |
4. | trash-rm | Remove specific files from trash. |
5. | trash-empty | Remove all the files in trash. |
To check the version of trash-cli, use the following command:
trash --version
Testing trash-cli
For testing purpose, create few files and directory:
touch file1.txt file2.txt
mkdir test
touch test/file3.txt
Move them to trash:
trash-put file1.txt file2.txt test
Get a list of files in trash:
trash-list
Output:
2024-08-15 15:48:48 /home/adminer/test
2024-08-15 15:48:48 /home/adminer/file1.txt
2024-08-15 15:48:48 /home/adminer/file2.txt
Trash directory can found in the ~/.local/share/Trash
. It contains files
and info
subdirectories:
trash
- stores trashed files.info
- stores information on where the files were located before deletion.
Files can be restored as follows:
trash-restore
It asks what files to restore. Enter the number:
0 2024-08-15 15:48:48 /home/adminer/test
1 2024-08-15 15:48:48 /home/adminer/file1.txt
2 2024-08-15 15:48:48 /home/adminer/file2.txt
What file to restore [0..2]: 1
A specific file can be removed from trash as follows:
trash-rm file2.txt
To remove everything from trash, use the following command:
trash-empty
Uninstall trash-cli
If trash-cli is no longer necessary, 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