trash-cli: Lets You Access ‘Trash’ from the Command-line in Ubuntu Linux

When you delete a file in GNU/Linux (while using a desktop environment), it doesn’t delete the file completely from the storage media. Instead, just like in MS Windows, it sends it to a temporary location called the ‘Trash’. So later, you can easily undelete files by accessing the ‘Trash’.

However, if you’re a heavy command-line user, then managing the ‘Trash’ directly from it can be a bit hectic. So, if you’re looking for an easy way to achieve that, then you might wanna try this simple but cool utility called ‘trash-cli’. It’s a command-lite tool that lets you access ‘Trash’ and view, search, restore and empty the files inside it with ease.

You can delete certain files (without deleting all), as long as they were put into the ‘Trash’ in the same day, but cannot use the names for deleting them individually. For instance, if you have like 5 files that were deleted yesterday and 3 that were deleted today, then with ‘trash-cli’, you can delete all the files that were deleted yesterday but, you cannot delete each file individually.

Other than that, it’s a great little tool that can come in real handy (if you’re someone like a system admin for instance). And also, because by default, if you use a command like ‘rm’ to remove a file, it completely deletes that file (without putting it into ‘Trash’, though you can change that, but it’s a bit of a work :D), but you can make ‘trash-cli’ to be launched whenever you run the ‘rm’ utility thus, those files will be moved into the ‘Trash’.


If interested, you can install ‘trash-cli’ in Ubuntu 12.10 Quantal Quetzal, 12.04 Precise Pangolin, 11.10 Oneiric Ocelot, 11.04 Natty Narwhal and 10.10 by using the below command in your Terminal window.

sudo apt-get install trash-cli

How to use it?

The ‘trash-cli’ package will install four ‘child’ programs: restore-trash (restores items), trash-empty (deletes files in ‘Trash’), trash-list (shows the list of files) and trash-put (deletes files into the ‘Trash’).

Few examples …

1. If I wanted to restore a certain file from my trash, then I’ll simply put the below command into the Terminal.


As you can see from the below screenshot, it’ll automatically display all the files inside the ‘Trash’ and you just have to enter the assigned number (marked in Blue) and press enter and that file will be restored to its original location.


2. As said before, unlike with ‘restore’, you cannot delete individual files (let’s hope the developer will add this option in the future), but can delete files that were deleted within a particular day.

For instance, if I have 3 files (one that was deleted yesterday and two that were deleted today), and only want to completely delete the file that was put to ‘Trash’ yesterday, first I’ll use the below command for first getting a list of files in the ‘Trash’ (so I know which files will be removed).



Then, after making sure that the file (s) that were deleted yesterday are not important anymore, I’ll use the below command to delete them from ‘Trash’.

trash-empty 1

Simply replace ‘1’ with the number of days that you want to go back and delete the files that were put to ‘Trash’ in that particular day.

3. If all you want is to completely delete all the files in the ‘Trash’, then enter the below command.


4. As said, if you don’t like the fact that tools like ‘rm’ just completely deletes files without sending them to ‘Trash’, then you can use ‘trash-put’ command for deleting files and it’ll send them to ‘Trash’.

For example, if I have a file called ‘2.mp3’ in my ‘Home’ folder, then I’ll use the below command for that.

trash-put 2.mp3

Again, please replace ‘2.mp3’ with your file’s name and its path.

Or, if you want to send files to ‘Trash’ whenever you use the ‘rm’ utility, then use the below command (this makes the OS run the ‘trash-put’ command when you run ‘rm’).

alias rm=’trash-put’

Well, that’s pretty much it. But please be careful while using it because when it comes to completely deleting files, it won’t ask for your conformation. Enjoy!.

An RHCE, 'Linux' user with 14+ years of experience. Extreme lover of Linux and FOSS. He is passionate to test every Linux distribution & compare with the previous release to write in-depth articles to help the FOSS community.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.