LinuxCommandLibrary

gio-trash

Move files or directories to the trash

TLDR

Move specific files to the trash bin

$ gio trash [path/to/file_or_directory1 path/to/file_or_directory2 ...]
copy

List trash bin items
$ gio trash --list
copy

Restore a specific item from trash using its ID
$ gio trash trash://[id]
copy

SYNOPSIS

gio trash [OPTION...] LOCATION...

PARAMETERS

LOCATION...
    One or more file paths or URIs specifying the files or directories to be moved to the trash. Directories are trashed recursively.

-d, --dry-run
    Performs a simulation of the trash operation without actually moving any files. This option prints what would be done.

-f, --force
    Ignores non-existent files and arguments, preventing errors when some specified paths do not exist.

-v, --verbose
    Enables verbose output, explaining what is being done during the trash operation.

-h, --help
    Displays a brief help message about the gio trash command and its options.

--version
    Shows the version information of the gio utility.

DESCRIPTION

The gio-trash command is a subcommand of the gio utility, which is a core component of the GLib/GIO library used primarily in desktop environments like GNOME. Unlike the rm command that permanently deletes files, gio-trash moves specified files or directories to the user's trash can, typically located at ~/.local/share/Trash. This allows for easy recovery of accidentally discarded items through a graphical file manager or by manually moving them from the trash directory. It leverages GIO's capabilities to handle various URI schemes, enabling trashing not only local files but also files on supported remote locations, offering a unified and desktop-integrated way of managing discarded items.

CAVEATS

Files moved to the trash are not permanently deleted; they consume disk space until the trash is explicitly emptied.
The trash location is typically user-specific, usually ~/.local/share/Trash.
Trashing might not be directly supported on all file systems or remote locations; in such cases, files might be permanently deleted or an error may occur.
This command relies on GLib/GIO and is primarily found in desktop Linux environments, not standard in minimal server installations.

RESTORING FILES

Files moved to the trash can usually be restored by opening the 'Trash' or 'Bin' folder in your graphical file manager (e.g., Nautilus, Dolphin, Thunar) and moving them back to their original location or a new desired location. Alternatively, you can manually navigate to ~/.local/share/Trash/files/ and move the desired files from there using the mv command, although this is less common.

EMPTYING TRASH

To permanently delete files from the trash and free up disk space, you typically need to use your graphical file manager's 'Empty Trash' or 'Empty Bin' option. There isn't a direct gio command designed specifically for emptying the entire trash folder, reinforcing its role as a tool for moving to trash rather than managing the trash contents themselves.

HISTORY

The gio utility, including gio-trash, is part of the GLib and GIO library, a foundational component of the GNOME desktop environment. It emerged as a modern, unified I/O layer, consolidating and often superseding older mechanisms like parts of GVFS (GNOME Virtual File System). gio-trash specifically provides the command-line equivalent of the 'Move to Trash' functionality found in graphical file managers, aligning with desktop conventions for managing discarded files. Its development reflects the ongoing evolution towards a more integrated and user-friendly file management experience in Linux desktop environments.

SEE ALSO

rm(1), mv(1), gio(1), gvfs-trash(1)

Copied to clipboard