Emacs: Dired Sort File by Time, Size 🚀
Here's a emacs command that lets you sort dired file listing by any {date/time, size, name}.
put this in your Emacs Init File:
(defun xah-dired-sort () "Sort dired dir listing in different ways. Prompt for a choice. URL `http://xahlee.info/emacs/emacs/dired_sort.html' Version: 2018-12-23 2022-04-07" (interactive) (let (xsortBy xarg) (setq xsortBy (completing-read "Sort by:" '( "date" "size" "name" ))) (cond ((equal xsortBy "name") (setq xarg "-Al ")) ((equal xsortBy "date") (setq xarg "-Al -t")) ((equal xsortBy "size") (setq xarg "-Al -S")) ((equal xsortBy "dir") (setq xarg "-Al --group-directories-first")) (t (error "logic error 09535" ))) (dired-sort-other xarg )))
Works in linux, MacOS, Microsoft Windows.
Give it a keybinding for easy call.
(require 'dired ) (define-key dired-mode-map (kbd "s") 'xah-dired-sort)