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.
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.
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.
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.
Discover more from Ubuntu-Server.com
Subscribe to get the latest posts sent to your email.