Emacs: Dired Customization

By Xah Lee. Date: . Last updated: .

This page is tips for setting up emacs's dired. See also: emacs dired basics.

How to hide the file's unix owner and permission info?

emacs dired-hide-details-mode
M-x dired-hide-details-mode. Top is normal dired, bottom is dired with hide details on.

In dired, Alt+x dired-hide-details-mode. Key is (.

If you want it always on, add a hook. Like this:

(defun xah-dired-mode-setup ()
  "to be run as hook for `dired-mode'."
  (dired-hide-details-mode 1))
(add-hook 'dired-mode-hook 'xah-dired-mode-setup)

How to sort files in dired?

Emacs: Dired Sort File by Time, Size

How to delete or copy a directory?

Put this in your emacs init:

;; allow dired to delete or copy dir
(setq dired-recursive-copies (quote always)) ; “always” means no asking
(setq dired-recursive-deletes (quote top)) ; “top” means ask once

Then in dired, Alt+x dired-do-deleteD】 to delete directory.

How to copy from one dired dir to the next dired dir shown in a split window?

Put this in your emacs init:

(setq dired-dwim-target t)

Eval the above or restart emacs. 〔►see How to Evaluate Emacs Lisp Code

Now, go to dired, then Alt+x split-window-below, then go to another dired dir. Now, when you press C to copy, the other dir in the split pane will be default destination. Same for dired-do-renameR】 and others.

How to make dired use the same buffer for viewing directory?

In dired, Alt+x dired-find-alternate-filea】 to open the file/directory without creating a new buffer.

If you want Enter ↵ and ^ (parent dir) to use the same buffer, put the following in your emacs init file:

(require 'dired )

(define-key dired-mode-map (kbd "RET") 'dired-find-alternate-file) ; was dired-advertised-find-file

(define-key dired-mode-map (kbd "^") (lambda () (interactive) (find-alternate-file "..")))  ; was dired-up-directory

How to hide some files?

Alt+x dired-do-kill-linesk】 to hide marked files.

File Related Tips

In a file, how to go to its directory and place cursor on the file name?

Put this in your init file:

(require 'dired-x)

In any file buffer, Alt+x dired-jumpCtrl+x Ctrl+j】 to jump to the directory of current buffer.

How to open a (image, pdf, doc) file in external apps?

See: Emacs: Open File in External App.

How to rename multiple files?

See: Emacs: Batch Rename Files.

Dired topics

  1. Emacs: File Manager, dired
  2. Emacs: Dired Customization
  3. Emacs: Find Replace Text in Directory
  4. Emacs: Batch Rename Files
  5. Emacs: Dired Sort File by Time, Size
  6. Emacs: Open File in External App
  7. Emacs: Rename File from Space to Hyphen/Underscore
  8. Emacs: Convert Image Files in Dired
Like it? Buy Xah Emacs Tutorial. Thanks.