Open, view, browse, restore or permanently delete trashed files or directories in trash can with Dired-like look and feel. In Emacs, You can trash files by deleting them with (setq delete-by-moving-to-trash t)
. This package provides a simple but convenient user interface to manage those trashed files. Supported trash cans are currently MS Windows Recycle Bin and freedesktop.org Trash Can.
This package is available on MELPA. You can install it with M-xpackage-installRETtrashedRET from within Emacs.
If you want to install manually, just put trashed.el
somewhere in your load path and add below to ~/.emacs.d/init.el
or ~/.emacs
.
(require 'trashed)
M-xtrashedRET, or use your favorite key binding like:
(global-set-key "\C-ct" 'trashed)
If (eq system-type 'windows-nt)
such as mingw Emacs, it accesses Windows Recycle Bin under $Recycle.Bin
folder in all drives. Otherwise such as Linux, it accesses freedesktop trash can under ~/.local/share/Trash
or somewhere else XDG_DATA_HOME
specifies. Windows XP or older is not supported.
Open, view or browse file with f, v or W. Open or display file in another window with o or Ctrl-o.
Restore file with R or permanently delete file with D. If you want to do the action for multiple files at one time, mark them with m and execute the action with R or D. You can also flag one or multiple files for restoration or deletion with r or d and then execute the action with x at one time. If you want to simply empty trash can, just type M to mark all and type D. Unmark or unmark all are done with u or U.
Regular expression based marking/flagging/unmarking can be used with %m, %r, %d or %u.
Date condition based marking/flagging/unmarking can be also used with $m, $r, $d, $u. Date condition must consist of <
(before) or >
(after), and N
days ago. For example, <365
means mark all files deleted before the day 1 year ago, >30
means mark all files deleted after the day 1 month ago, >1
means mark all files deleted today.
Sorting key or order can be changed by moving column with TAB or Shift-TAB to choose the key for sorting and typing S. Typing S again reverts the sorting order.
You can use mouse for the operations above via right click menu or menu bar.
See more information with C-hm.
trashed-use-header-line
Non-nil means Emacs window's header line is used to show the column names. Otherwise, text based header line is used.
trashed-sort-key
Default sort key. If nil, no additional sorting is performed. Otherwise, this should be a cons cell (COLUMN . FLIP). COLUMN is a string matching one of the column names. FLIP, if non-nil, means to invert the resulting sort.
trashed-size-format
Trash file size format displayed in the list. Options are below. Appropriate column width is set automatically.
- plain -- Plain number
- human-readable -- Human readable number formatted with
file-size-human-readable
- with-comma -- Number with comma every 3 digits
trashed-date-format
Deletion date format displayed in the list. Formatting is done with the function format-time-string
. This actually allows you to configure wide variety of format and display it appropriately according to your system locale setting. See the function's description for details with C-hfformat-time-string. Appropriate column width is set automatically.
trashed-action-confirmer
- Confirmer function to ask if user really wants to execute requested action.
yes-or-no-p
ory-or-n-p
. If you really don't need any confirmation, you can set below at your discretion.
(defun always-yes-p (prompt) t)
(setq trashed-action-confirmer 'always-yes-p)
trashed-load-hook
Run after loading Trashed.
trashed-mode-hook
Run at the very end of trashed-mode
.
trashed-before-readin-hook
Run before Trash Can buffer is read in (created or reverted).
trashed-after-readin-hook
Run after Trash Can buffer is read in (created or reverted).
Trashed can be also used from within Emacs Lisp code for trash can maintenance. For example, below code in ~/.emacs.d/init.el
or ~/.emacs
deletes trashed files which were deleted 1 years ago or before every time Emacs is killed.
(defun always-yes-p (prompt) t)
(add-hook 'kill-emacs-hook
#'(lambda ()
(let ((trashed-action-confirmer 'always-yes-p))
(trashed)
(trashed-flag-delete-files-by-date "<365")
(trashed-do-execute))))
- Menu bar
- Date based marking (mark files 1 month ago or older, etc)
- Support MS Windows Recycle Bin
- ...any request/suggestion is appreciated