(or emacs irrelevant)

File sizes in dired

Today, I'll continue with the trend of posting a small piece of my config when I don't have the time to post something more substantial.

Some code

This one looks nice, although it only works on systems with /usr/bin/du, which actually comprise 100% of the systems that I use:

(defun dired-get-size ()
  (let ((files (dired-get-marked-files)))
      (apply 'call-process "/usr/bin/du" nil t nil "-sch" files)
       "Size of all marked files: %s"
         (re-search-backward "\\(^[ 0-9.,]+[A-Za-z]+\\).*total$")
         (match-string 1))))))

On doing a search, turns out that I got this code from the wiki at some point. I can confirm that, unlike some of the other code on the wiki, this one still works as advertised: you can use it on a directory or on a series of marked files and directories.

Standard dired marking

In dired, you can:

  • mark an item with m
  • unmark an item with DEL
  • inverse selection with t
  • unmark everything with U

Compared to this, the selection with the mouse and the control and shift keys that many file browsers use looks like kindergarten.

This new action, getting the size of marked things, I've bound to z:

(define-key dired-mode-map (kbd "z") 'dired-get-size)