Menu

Documentation about Emacs' dired Mode

dired is Emacs built-in tool to work with directories and files. It resembles the "commander" like tools which go beyond the command line, but are not graphical in a modern sense. You will find that dired is immensely powerful.

To enter dired-mode do

C-x d directory <RET>

or

M-x dired

Searching Files

When the files are all in the same directory or in not too many sub-directories:

Searching for Files

The find-dired command lets you run arbitrary 'find' commands, then displays the results in a dired buffer, including arbitrarily nested subdirectories.

E.g. to list all executable files containing the string "foo", case insensitively, rooted at /usr:

M-x find-dired <RET> //usr <RET> -iname "*foo*" -executable -type f

Navigating the directory tree

Move up one directory (this opens a new dired buffer):

^

Enter a directory without opening a new buffer (in contrast to f oder RET):

a

Move a file or a whole directory:

R

Use the up- or down-arrow in Emacs' mini-buffer to select a target path; paths in other Emacs windows will feature.

Do dired of the directory of the file you are currently editing:

M-x dired-jump

Manually input a path (like CD xyz):

C-x d

Working with Directory Information

The last option deserves more explanation: there is the notion of default-directory for each Emacs buffer. For a dired buffer, this directory is normally the directory shown by dired. However, you can set default-directory using M-x cd. Thus C-u w will yield a non-trivial relative path.

Choosing Which External Commands Get Launched

You can associate further file extensions with external commands, to open them from dired, e.g.

(add-to-list 'dired-guess-shell-alist-user '("\.mkv\'" "vlc"))

This complements what the variable dired-guess-shell-alist-default specifies.

Adapting the View

Toggling sorting between date and name:

s

To sort by size:

C-u s S

the big S is ls format option by size

Toggling detailed and terse view:

(

Get two "panes" (Emacs windows):

M-x split-window-horizontally

which is an alias of split-window-right

Menu-bar -> File -> new-window-on-right

Or simply do

C-x 3

Switch between windows ("other" window):

C-x o 

To go back to one pane only:

C-x 1

Various

Listing a directory via FTP:

/ftp:user@host.tld:/directory/

The :/directory/ part seems to be mandatory

To copy the dired path to the clipboard, move the cursor to top dired window line (i.e. the one with the path):

w

The path will end with a slash. Note: also under MS Windows this will yield forward slashes. However, the Windows tools accept paths with forward slashes too.

My dired Customisations

I customised dired-listing-switches to "-Al")

To sort directories at the top and hide hidden files:

(setq dired-listing-switches "-lF --group-directories-first")

On Windows, dired is using a Lisp emulation of ls. My preferences:

Combining dired with speedbar

speedbar is Emacs built-in tool to explore directory trees, like you it in various graphical user interfaces. You start speedbar with

M-x speedbar

The speedbar is bound to the active frame and lives in its own frame.

speedbar can be used together with dired. C-x d works in a speedbar frame as well. It offers to dired speedbar's "current" directory. However, that directory is the one shown at the top of the speedbar frame, not something in the tree that you might have opened below. In other words: you need to go down to the wanted directory and use RET to make it current. BTW: U (shift-u) sets speedbar's current directory "up" one level.


Last change: 2023-10-22
© 2002-2023 Dr. Thomas Redelberger redethogmx.de

Close menu