LinuxCommandLibrary

trash

Move files and directories to trash

TLDR

Send a file to the trash

$ trash [path/to/file]
copy

List all files in the trash
$ trash-list
copy

Interactively restore a file from the trash
$ trash-restore
copy

Empty the trash
$ trash-empty
copy

Permanently delete all files in the trash which are older than 10 days
$ trash-empty 10
copy

Remove all files in the trash, which match a specific blob pattern
$ trash-rm "[*.o]"
copy

Remove all files with a specific original location
$ trash-rm /[path/to/file_or_directory]
copy

SYNOPSIS

trash-put [OPTIONS] FILES...

PARAMETERS

-f, --force
    Ignore non-existent files and arguments, never prompt.

-v, --verbose
    Explain what is being done by showing moved files.

--debug
    Display verbose debugging messages.

--version
    Show program's version number and exit.

-h, --help
    Show help message and exit.

FILES...
    One or more files or directories to be moved to the trash.

DESCRIPTION

The trash-put command, often aliased simply as trash on many systems, provides a safer alternative to the rm command for deleting files from the command line. Unlike rm which permanently removes files, trash-put moves them to the freedesktop.org compatible trash bin, allowing for later recovery. This behavior mirrors the "Recycle Bin" or "Trash" functionality found in graphical desktop environments.

When a file or directory is "trashed," it is moved to a special location, typically ~/.local/share/Trash/, where its original path and deletion date are also recorded. This design prevents accidental permanent data loss and provides a convenient way to manage deleted items. trash-put is part of the trash-cli suite, a set of command-line tools designed to interact with the freedesktop.org trash specification.

CAVEATS

trash-put is not a default command on all Linux distributions and typically requires installation of the trash-cli package.

It relies on the freedesktop.org trash specification, which means it integrates well with desktop environments but might not be ideal for minimal server setups without a desktop environment.

Trashing files does not immediately free up disk space if the trash bin resides on the same filesystem. Space is only reclaimed when the trash is emptied.

When trashing files located on a different filesystem, trash-put might copy the files to the trash bin and then delete the originals, which can be slower and consume more space temporarily for large files.

THE <B>TRASH-CLI</B> SUITE

The trash-put command is part of a larger collection of tools provided by the trash-cli package, all designed to interact with the freedesktop.org trash specification. Other commands in this suite include:

  • trash-list: To view all items currently in your trash bin.
  • trash-restore: To interactively restore specific items from the trash back to their original location (or a specified one).
  • trash-empty: To permanently delete all items in the trash, optionally specifying items older than a certain number of days.
  • trash-rm: To permanently remove specific items from the trash without emptying the entire bin.

These commands together provide comprehensive command-line management of trashed files.

FREEDESKTOP.ORG TRASH SPECIFICATION

The freedesktop.org trash specification defines how trash bins should behave on Linux and other Unix-like systems. It mandates that trashed files are moved to a Trash directory, typically located at ~/.local/share/Trash/. Inside this directory, two subdirectories are found: files/ (where the actual trashed items reside) and info/ (which contains metadata files (.trashinfo) detailing the original path and deletion date for each trashed item). This standardized approach ensures that files trashed via the command line (e.g., with trash-put) are visible and manageable by graphical file managers and vice-versa.

HISTORY

The concept of a "trash bin" or "recycle bin" originated in graphical user interfaces to provide a safety net for file deletion. As command-line usage remained prevalent, a need arose for similar functionality outside of graphical environments. The freedesktop.org trash specification emerged to standardize this behavior across various Linux desktop environments. trash-cli (and thus trash-put) developed as a popular open-source implementation to bring this standardized trash management to the command line, offering a robust and recoverable alternative to the destructive nature of rm. Its development focused on user convenience and data safety, evolving to integrate seamlessly with desktop trash functionalities.

SEE ALSO

Copied to clipboard