
In this guide, we will explore different methods of emptying the trash using the terminal in Ubuntu. This is a useful skill for system administrators and users who prefer to work in a terminal environment.
To empty the trash using the terminal in Ubuntu, you can use the rm
command with the following command: rm -rf ~/.local/share/Trash/*
. Additionally, you can install and use the trash-cli
package with the command trash-empty
. Another option is to use the gvfs-trash
command with the --empty
flag. Alternatively, you can use a script to empty the trash across different drives and locations.
Using the rm
Command
The rm
command is a fundamental command used in UNIX and UNIX-like operating systems, including Ubuntu. rm
stands for ‘remove’. Here is how you can use it to empty the trash:
- Open the terminal.
- Type the following command and press Enter:
rm -rf ~/.local/share/Trash/*
Let’s break down this command:
rm
: This is the remove command.-rf
: These are options passed to therm
command. The-r
or-R
option tellsrm
to remove directories and their contents recursively. The-f
option tellsrm
to ignore nonexistent files and arguments, and never prompt.~/.local/share/Trash/*
: This is the path to the trash directory. The~
represents the current user’s home directory, and the*
at the end is a wildcard that matches all files and directories.
Please be cautious when using the rm
command. It permanently deletes files, and you cannot recover them from the trash can.
Installing and Using trash-cli
trash-cli
is a command-line interface for trashcan following the Freedesktop.org Trash Specification. Here is how you can install and use it:
- Open the terminal.
- Install
trash-cli
by running the following command:
sudo apt install trash-cli
- Once installed, you can empty the trash by running:
trash-empty
Using gvfs-trash
GVFS (GNOME Virtual File System) provides a set of APIs and a virtual file system that allows applications to access stored files. Here is how you can use it to empty the trash:
- Open the terminal.
- Run the following command:
gvfs-trash --empty
Using a Script
You can also use a script to empty the trash across different drives and locations. One such script can be found here. Please make sure to read and understand the script before using it.
Conclusion
In this guide, we have covered various ways to empty the trash using the terminal in Ubuntu. Remember to be cautious when using commands like rm
, as they can permanently delete files. Always double-check the commands you are running, especially when logged in as the root user.
No, files deleted using the rm
command are permanently deleted and cannot be recovered from the trash can. Please exercise caution when using this command.
Yes, it is safe to use the rm
command as long as you are certain about the files you want to delete. However, please be cautious as it permanently deletes files and they cannot be recovered from the trash can.
No, once you empty the trash using the trash-cli
or gvfs-trash
methods, the files are permanently deleted and cannot be recovered. Please make sure you have a backup of any important files before emptying the trash.
Yes, the trash-cli
and gvfs-trash
methods can be used on other Linux distributions that support the freedesktop.org Trash Specification and have the necessary packages installed. However, the installation process may vary depending on the distribution.
In general, once the trash is emptied, the files are permanently deleted and cannot be easily recovered. However, there are some specialized data recovery tools available that may be able to recover deleted files. It is recommended to consult a professional data recovery service if you need to recover important files.