GNU Emacs
Emacs
Dashboard

30.11 Subdirectories in Dired

A Dired buffer usually displays just one directory, but you can optionally include its subdirectories as well.

The simplest way to include multiple directories in one Dired buffer is to specify the options ‘ -lR’ for running ls. (If you give a numeric argument when you run Dired, then you can specify these options in the minibuffer.) That produces a recursive directory listing showing all subdirectories at all levels.

More often, you will want to show only specific subdirectories. You can do this with i ( dired-maybe-insert-subdir):

i

Insert the contents of a subdirectory later in the buffer.

If you use this command on a line that describes a file which is a directory, it inserts the contents of that directory into the same Dired buffer, and moves there. Inserted subdirectory contents follow the top-level directory of the Dired buffer, just as they do in ‘ ls -lR’ output.

If the subdirectory’s contents are already present in the buffer, the i command just moves to it.

In either case, i sets the Emacs mark before moving, so C-u C-SPC returns to your previous position in the Dired buffer (see Setting the Mark). You can also use ‘ ^’ to return to the parent directory in the same Dired buffer (see Visiting Files in Dired).

Use the l command ( dired-do-redisplay) to update the subdirectory’s contents, and use C-u k on the subdirectory header line to remove the subdirectory listing (see Updating the Dired Buffer). You can also hide and show inserted subdirectories (see Hiding Subdirectories).