Emacs: File Management (dired tutorial)

Buy Xah Emacs Tutorial. Master emacs benefits for life.
, , …,

Emacs is a excellent tool for file management. For example, list files, copy/delete, rename, moving files, create/delete directory. Once you become familiar with it, you almost never go to shell or the OS desktop for these tasks.

emacs dired
M-x dired. emacs's feature for file management.

“dired” is short for Directory Edit. It is a old term for file management.

{Copy, Delete, Rename} File

To start viewing directory, called dired.

When in dired, most commands have a single letter key.

emacs dired menu 2015-10
emacs dired “Operate” menu

Here's the most useful commands:

Enter ↵dired-find-fileOpen the file or directory.
qquit-windowDone. Display last buffer. (call kill-buffer if you actually want to close it.)
Cdired-do-copyCopy file
Rdired-do-renameRename/move file
Ddired-do-deleteDelete file or directory
+dired-create-directorycreate new dir
Zdired-do-compresscompress/decompress the file by gzip

Mark/Unmark Multiple Files

Sometimes you want to copy or delete many files. You can mark the files, then apply a command on all marked files.

To mark a file, press m. Here's a list of basic marking commands:

basic dired marking commands
mdired-markmark a file
Udired-unmark-all-marksunmark all marked
% mdired-mark-files-regexpmark by pattern (regex)

For example, if you want to mark all HTML files, type 【% m】, then type \.html$.

Dired Navigation

Here are other common dired commands:

basic dired navigation commands
grevert-bufferrefresh dir listing
^dired-up-directorygo to parent dir
>dired-next-dirlineMove cursor to next subdirectory.
<dired-prev-dirlineMove cursor to previous subdirectory.

dired is often used together with shell-commandAlt+!】 or shell. 〔➤ Emacs: Run Shell in Emacs

For complete list of dired commands, call describe-mode when in dired-mode.

(info "(emacs) Dired")

Renaming Many Files

See: Emacs: Rename Files Interactively.

Open File (PDF, image, …) in External App

Emacs Lisp: Open File in External App

Dired Settings

dired has many features and options.

Like it? Buy Xah Emacs Tutorial.
blog comments powered by Disqus