5.2 Using Dired, the Directory Editor
Dired is one of the most interesting features of Emacs. With Dired, 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. 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 literature
Emacs starts up editing the directory literature: you'll see a single window that contains a listing of the literature 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 file. For example, typing C-x C-f literature gets you ready to edit the literature directory. Typing C-x d (for dired) or selecting the folder icon on the toolbar also starts Dired; you then specify a directory name. Finally, dragging a folder onto the Emacs window also starts Dired.
No matter how you start the editor, the result is the same.
Type: C-x C-f literature Enter
A basic directory editor display.
As you can see, Dired's display is similar to what you see if you type ls -l at a Unix shell prompt. The permissions associated with the file, the owner, the group name, the size of the file, and the date last modified all precede the filename. All files and directories are listed, including those whose names start with a dot. The cursor starts out on a filename, rather than in the first column.
Also, if your display supports colors (unfortunately this book doesn't), you'll see that directories are blue, backup and auto-save files are tan, and symbolic links are purple. Colors are a function of font-lock mode. If you don't see colors in your directory listing, type M-x font-lock-mode Enter or add the following line to your .emacs file:
By default, the list is sorted by filename, but you can sort it by date instead. Look at the mode line. It says (
Dired by name). To change the order of the display, type s (for dired-sort-toggle-or-edit). This command puts the newest files at the top of the list, solving the "Where's that file I worked on yesterday?" problem quite easily. The mode line says (
Dired by date). Typing s again toggles the sort, putting it back in alphabetical order.
If you remember the commands used to edit the buffer list (from Chapter 4), you will find that they are almost identical to the directory editor commands. You can do many additional things, but the basic commands are the same.
- Table E-12. Dired commands
- Безопасность внешних таблиц. Параметр EXTERNAL FILE DIRECTORY
- 4.4.4 The Dispatcher
- ТМР DIRECTORY
- EXTERNAL FUNCTION DIRECTORY
- About the author
- Chapter 7. The state machine
- Appendix E. Other resources and links
- Caveats using NAT
- Example NAT machine in theory
- Using Double Quotes to Resolve Variables in Strings with Embedded Spaces
- The final stage of our NAT machine