Categories: TutorialsUbuntu

How to Empty Trash in Ubuntu from Command Line

When you delete a file in your system, it goes to Trash. Its purpose is to enable the users to restore the files that were deleted accidentally. However, when you empty the trash, all the files are deleted permanently. Emptying the trash on regular basis can help you to free up some disk space on your system. On Linux systems, you can empty trash both using the graphical interface and the command line.

In today’s post, we will show how to empty trash in Ubuntu from the command line (Terminal). This post is intended for the users who prefer the command line for handling their everyday tasks.

Sponsored

Note: The files or directories deleted by the rm command do not go into Trash. Instead, they are permanently removed from the system. Therefore, you should be careful before deleting a file or a directory through the rm command.

Table of Contents

Toggle

Method#1

In this method, we will empty the trash in Ubuntu through the Terminal using the rm command. You can open the Terminal in Ubuntu using the Ctrl+Alt+T shortcut. Let’s get started.

1. Navigate to the directory where trash files are stored. You can do so through the command below:

$ cd ~/.local/share/Trash/files/

2. To view the deleted files that are stored in Trash, run the command below:

$ ls

3. To empty the trash, run the command below:

$ rm -rf *

Make sure you are in the ~/.local/share/Trash/files/ directory before running the above command.

This command will empty the Trash. You can verify this through the command below:

$ ls

Method#2

In this method, we will empty the trash in Ubuntu through the Terminal using the trash-cli utility. You can open the Terminal in Ubuntu using the Ctrl+Alt+T shortcut. Let’s get started.

Sponsored

1. Install trash-cli utility through the command below:

$ sudo apt install trash-cli

Enter the sudo password. After you have entered the password, it will ask if you want to carry on the operation. Hit y and then the Return key.

This will install the trash-cli utility on your Ubuntu system.

2. To view the deleted files that are stored in Trash, run the command below:

$ trash-list

3. To empty the trash using the trash-cli utility, run the command below:

$ trash-empty

This command will empty the trash. You can verify this through the command below:

$ trash-list

This is how you can empty trash in Ubuntu from the command line. This task should be done regularly in order to free up some space in your system. If you find this task tedious, you can automate the procedure of emptying the trash. Visit this post for the complete procedure.

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.

Ubuntu Server Admin

Recent Posts

How to Fix VMware’s “Could not open /dev/vmmon” Error on Ubuntu

You’ve recently installed VMware Workstation on your Ubuntu system and encountered the frustrating “Could not…

5 hours ago

How to Fix Ubuntu 404 Errors While Fetching Dependencies

Have you ever found yourself staring at a terminal full of 404 errors while trying…

5 hours ago

How to Fix ‘Please Install All Available Updates’ Error When Upgrading Ubuntu 18.04 to 20.04 LTS

One particularly frustrating error that many users face when trying to upgrade from Ubuntu 18.04 …

5 hours ago

How to fix “Release is not valid yet” Error in Docker Containers

In the world of containerization, time synchronization issues can create unexpected roadblocks when working with…

5 hours ago

How to fix “Externally Managed Environment” Pip Errors on Ubuntu

If you’ve recently upgraded to Ubuntu 23.04 or newer, you might have encountered a frustrating…

5 hours ago

Ubuntu now officially supports NVIDIA Jetson: powering the future of AI at the edge

Canonical announces the General Availability of Ubuntu for the NVIDIA® Jetson Orin™ for edge AI…

12 hours ago