How to Send Files to the Trash Can in Linux with Gio Trash

When you run out of disk space or want to remove unnecessary files to increase server security, you may end up deleting a lot of files in a short period of time. If you’re in the Linux terminal / SSH, you’ll likely use the rm command. But this permanently deletes files (excluding data recovery methods) and can result in you having to restore from backup files if you delete the wrong file(s). The solution may already be on your machine.

The gio trash command will send files to your trash can for later review. It’s pre-installed on many Linux operating systems (OSs) and the successor to gvfsd-trash.

It’s important to remember that gio trash sends files to ~/.local/share/Trash/files instead of ~/.trash, used on cPanel managed servers.

The .local/share/Trash directory includes three directories:

  • info stores deleted files’ original location and deletion time
  • files stores deleted files until it’s emptied
  • expunged may temporarily hold recently emptied trash

Below we cover how to send files to the trash can and permanently delete files with gio.

Try our Cloud Server Hosting today and upgrade your disk space anytime without downtime.

Send Files to Trash with gio trash

  1. Open your terminal
  2. Move files to .trash:
    gio trash [FILE1] [FILE2]
  3. View the trash in .local/share/Trash/files:
    gio list trash://

    Or
    ls ~/.local/share/Trash/files
  4. Empty the trash can:
    gio trash --empty

man gio | grep trash

Below is the man gio trash information:

man gio | grep trash
trash [OPTION...] [LOCATION...]
Sends files or directories to the "Trashcan". This can be a different folder depending on where the file is located, and not all file systems support this concept. In the common case that the file lives inside a users home directory, the trash folder is $XDG_DATA_HOME/Trash.

Note that moving files to the trash does not free up space on the file system until the "Trashcan" is emptied. If you are interested in deleting a file irreversibly, see the remove command.

Inspecting and emptying the "Trashcan" is normally supported by graphical file managers such as nautilus, but you can also see the trash with the command: gio list trash://.

Options
-f, --force
Ignore non-existent and non-deletable files.

--empty
Empty the trash.

Use gio help trash for short a short summary.

Delete Files Permanently with gio remove

You can also permanently remove files with the gio remove command:

gio remove [FILE1] [FILE2]

Use the -f option to ignore non-existent and non-deletable files:

gio remove -f [FILE1] [FILE2] [FILE3]

The trash and delete options are also available in popular GUI applications.

What lesser known Linux commands do you know? Let us know in our Community Support Center.

InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

Was this article helpful? Join the conversation!

Questions about our MailChannels Deployment? We have answers and are here to help!Learn More
+