A command line interface to the freedesktop.org trashcan. It trashes files recording the original path, deletion date, and permissions. It uses the same trashcan used by KDE, GNOME, and XFCE.
# Via Homebrew (Linux/macOS)
brew install trash-cli
# Via pip
pip install trash-cli
# Via apt (Debian/Ubuntu)
sudo apt install trash-cli
# Via pacman (Arch Linux)
sudo pacman -S trash-cli
# Via dnf (Fedora)
sudo dnf install trash-cli
| Command | Description |
|---|---|
| --------- | ------------- |
trash-put | Move files/directories to trash |
trash-list | List trashed files |
trash-restore | Restore trashed files |
trash-empty | Permanently delete trashed files |
trash-rm | Remove specific files from trash |
Move files or directories to the trash can.
trash-put <file> # Trash a file
trash-put <dir>/ # Trash a directory
trash-put -f <file> # Silently ignore nonexistent files
trash-put -v <file> # Verbose output
-f, --force - Silently ignore nonexistent files-v, --verbose - Explain what is being done--trash-dir TRASHDIR - Use TRASHDIR as trash folderrm, trash-put does not require -R for directories~/.local/share/Trash/$partition/.Trash/$uid or $partition/.Trash-$uidList all trashed files.
trash-list # List all trashed files
trash-list | grep <pattern> # Search for specific files
trash-list --all-users # List trashcans of all users
2008-06-01 10:30:48 /home/user/bar
2008-06-02 21:50:41 /home/user/baz
Format: deletion_date original_path
Restore trashed files to their original location.
trash-restore # Interactive restore
trash-restore --overwrite # Overwrite existing files
trash-restore --sort date # Sort by date (default)
trash-restore --sort path # Sort by path
$ trash-restore
0 2007-08-30 12:36:00 /home/andrea/foo
1 2007-08-30 12:39:41 /home/andrea/bar
2 2007-08-30 12:39:41 /home/andrea/baz
What file to restore [0..2]: 0
0-2,3 to restore multiple files--overwrite to replace existing filesPermanently remove files from trash.
trash-empty # Remove ALL trashed files
trash-empty 7 # Remove files older than 7 days
trash-empty 1 # Remove files older than 1 day
# Delete everything in trash
trash-empty
# Keep only files from the last 7 days
trash-empty 7
# Keep only today's files
trash-empty 1
Remove specific files from trash (by pattern).
trash-rm <pattern> # Remove files matching pattern
trash-rm '*.o' # Remove all .o files
trash-rm foo # Remove all files named "foo"
trash-rm /full/path # Remove by original path
Note: Use quotes to protect pattern from shell expansion.
trash-rm '*.log' # Correct
trash-rm *.log # Wrong - shell will expand
Add to .bashrc or .zshrc:
# Remind yourself not to use rm directly
alias rm='echo "Use trash-put instead!"; false'
# Or use a safer alias
alias rm='trash-put'
To bypass the alias when you really need rm:
\rm file.txt
trash-listtrash-list | grep trash-restore~/.local/share/Trash/$mount_point/.Trash/$uid or $mount_point/.Trash-$uidIf you need to create a trash directory on a different partition:
sudo mkdir --parent /.Trash
sudo chmod a+rw /.Trash
sudo chmod +t /.Trash
The author advises against this. Although trash-put seems compatible with rm, it has different semantics that will cause problems. For example, while rm requires -R for deleting directories, trash-put does not.
Instead, use a warning alias:
alias rm='echo "This is not the command you are looking for."; false'
To bypass when you really need rm:
\rm file.txt
共 1 个版本