Software & AppsOperating SystemLinux

How To Empty Trash Using Terminal in Ubuntu

Ubuntu 15

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.

Quick Answer

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:

  1. Open the terminal.
  2. 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 the rm command. The -r or -R option tells rm to remove directories and their contents recursively. The -f option tells rm 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:

  1. Open the terminal.
  2. Install trash-cli by running the following command:
sudo apt install trash-cli
  1. 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:

  1. Open the terminal.
  2. 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.

Can I recover files deleted using the `rm` command?

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.

Is it safe to use the `rm` command to empty the trash?

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.

Can I undo the emptying of the trash using the `trash-cli` or `gvfs-trash` methods?

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.

Can I use the `trash-cli` or `gvfs-trash` methods on other Linux distributions?

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.

Is there any way to recover files after emptying the trash?

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.

Leave a Comment

Your email address will not be published. Required fields are marked *