Working with Files and Directories

Dired, the directory editing mode, is one of the most interesting features of Emacs. It provides a way of editing a directory. You can look at a listing of all the files in a directory, delete them, rename them, copy them, and perform almost all basic file operations. Once you have gotten used to Dired, you never need the UNIX cp, rm, or mv commands. More important, Dired can make you more productive. For example, you can work with groups of files, deleting, moving, compressing, or even query-replacing strings in them.

There are several ways to start directory editing. If you’re not in Emacs, invoke Emacs with a directory name as an argument, for example:

% emacs fiction

Emacs starts up editing the directory fiction: you’ll see a single window, which contains a listing of the fiction directory. You can also start the directory editor by using C-x C-f (or any other command for visiting a file) and naming a directory, rather than a plain file. For example, typing C-x C-f fiction gets you ready to edit the fiction directory. Typing C-x d (for dired) or selecting Open Directory from the Files menu also starts Dired; you then specify a directory name. No matter how you start the editor, the result is the same.

Type: C-x C-f fiction RETURN

Working with Files and Directories

You now see a basic directory editor display.

As you can see, Dired’s display is similar to what you see when you ...

Get Learning GNU Emacs, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.