Install trash-cli on Ubuntu 22.04

Install trash-cli on Ubuntu 22.04

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 22.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:

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.

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:



2023-04-01 04:10:00 /home/adminer/file2.txt
2023-04-01 04:10:00 /home/adminer/file1.txt
2023-04-01 04:10:00 /home/adminer/test

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:


It asks what files to restore. Enter the number:

   0 2023-04-01 04:10:00 /home/adminer/file2.txt
   1 2023-04-01 04:10:00 /home/adminer/file1.txt
   2 2023-04-01 04:10:00 /home/adminer/test
What file to restore [0..2]: 2

A specific file can be removed from trash as follows:

trash-rm file2.txt

To remove everything from trash, use the following command:


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

Your email address will not be published.