File Management with Emacs (dired tutorial)

Advertise Here

, 2006, …,

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

emacs dired
A Screenshot of emacs's feature for file management.

Copy, Delete, Rename a File

To start viewing directory, type 【Ctrl+x d】, then type the dir you want. (Or, use the graphical menu 〖File▸Open Directory…〗.) You can now use arrow keys to move around. To open a file, just move cursor to it and press Enter. To view a subdir, just move cursor to it and press Enter. To close the current dir, type q.

Here's a list of common basic commands:

KeyPurpose
EnterOpen the file
qClose the dir
CCopy file
RRename file
DDelete file
+create a new dir
Zcompress/decompress the file by gzip
the Operate menu in Emacs's dired mode
Emacs's dired mode's Operate menu.

Mark/Unmark to Operate on Multiple Files

Sometimes you want to copy or delete many files. Instead of using the command on one file at a time, you can simply mark the files you want, then apply a command on all marked files. To mark a file, press m. Here's a list of basic marking commands:

KeyPurpose
mmark a file
uunmark
Uunmark all marked
% mmark by file name extension
% mmark by pattern (regex)

For example, if you want to mark all HTML files, type 【* .】, then type html.

Once you've marked, you can type any of the key for rename, copy, delete, …. When there are marked files, commands applies to the marked files. When no files are marked, commands applies to the file under cursor.

Dired Navigation

The keyboard shortcut 【Ctrl+x d】 calls the command dired. “dired” is short for Directory Edit. It is a old term for file management.

Here are other common dired commands:

KeyPurpose
grefresh dir listing
^go to parent dir

dired is often used in combination with 【Alt+!】 (shell-command). For example, suppose you downloaded a program and is going thru the install process of unzip, untar, configure, make, sudo make install. You can either run these command inside a emacs shell with 【Alt+x shell】, or you can just execute them one at a time with 【Alt+!】. For more about working with shell, see: Emacs Shell Tutorial (Bash, cmd.exe, PowerShell).

Menu as Cheatsheet

When you are in dired mode, there are 3 new graphical menus: 〖Operate〗, 〖Mark〗, 〖Regex〗. These menus lists the commands specific to dired. They are very useful as a cheatsheet. So, if you forgot what's the key to press to do something, look up in these menus.

(info "(emacs) Dired")

Renaming Many Files

See: Emacs: Rename Files Interactively by Pattern (regex; wdired).

Advanced Dired Tips and Settings

For more dired tips, see:

blog comments powered by Disqus