5

In emacs dired-mode, when I press s I can toggle between alphabetical and chronological sorting of files. Usually, I always prefer chronological sorting, but alphabetical sort is the default. How can I customize emacs to always have a dired buffer first show up chronologicaly sorted?

Christian Herenz
  • 434
  • 4
  • 16
  • 2
    Customize the variable `dired-listing-switches` -- it's basically the `ls` command *string* that has certain limitations based on the particular `ls` version installed, and `dired-mode` doesn't accept a `list` format (so I created my own custom version of dired that supports a list). See also this helpful library: http://www.emacswiki.org/emacs/dired-sort.el – lawlist Feb 08 '15 at 16:56
  • @lawlist points to one Emacs Wiki page that covers this topic. [**Here**](http://www.emacswiki.org/emacs/DiredSorting) is the page that deals with the topic generally. It covers multiple libraries that help with Dired sorting. – Drew Feb 09 '15 at 02:30

2 Answers2

4

I am just repeating @lawlist comment:

Customize the variable dired-listing-switches

For example: M-x customize-variable RET dired-listing-switches
Fill the field with -lt

Or just setq it in your .emacs or init.el with:

(setq dired-listing-switches "-lt")

nephewtom
  • 2,877
  • 2
  • 16
  • 17
  • I wrongly thought this solution would disable the possibility to sort alphabetically, since now `-t` option would always be present. However, this is not the case, and pressing `s` in `dired-mode` now toggles to alphabetically sorted, exactly what OP (and I) wanted. Thanks. – Axel Bregnsbo Oct 31 '21 at 07:03
0

I recently discovered this package in melpa, which makes (persistent) sorting in dired very easy: https://gitlab.com/xuhdev/dired-quick-sort

Christian Herenz
  • 434
  • 4
  • 16