GNU Emacs
Emacs
Dashboard

30.15 Updating the Dired Buffer

This section describes commands to update the Dired buffer to reflect outside (non-Dired) changes in the directories and files, and to delete part of the Dired buffer.

g

Update the entire contents of the Dired buffer ( revert-buffer).

l

Update the specified files ( dired-do-redisplay). You specify the files for l in the same way as for file operations.

k

Delete the specified file lines—not the files, just the lines ( dired-do-kill-lines).

s

Toggle between alphabetical order and date/time order ( dired-sort-toggle-or-edit).

C-u s switches RET

Refresh the Dired buffer using switches as dired-listing-switches.

Type g ( revert-buffer) to update the contents of the Dired buffer, based on changes in the files and directories listed. This preserves all marks except for those on files that have vanished. Hidden subdirectories are updated but remain hidden.

To update only some of the files, type l ( dired-do-redisplay). Like the Dired file-operating commands, this command operates on the next n files (or previous -n files), or on the marked files if any, or on the current file. Updating the files means reading their current status, then updating their lines in the buffer to indicate that status.

If you use l on a subdirectory header line, it updates the contents of the corresponding subdirectory.

If you use C-x d or some other Dired command to visit a directory that is already being shown in a Dired buffer, Dired switches to that buffer but does not update it. If the buffer is not up-to-date, Dired displays a warning telling you to type g to update it. You can also tell Emacs to revert each Dired buffer automatically when you revisit it, by setting the variable dired-auto-revert-buffer to a non- nil value.

To delete file lines from the buffer—without actually deleting the files—type k ( dired-do-kill-lines). Like the file-operating commands, this command operates on the next n files, or on the marked files if any. However, it does not operate on the current file, since otherwise mistyping k could be annoying.

If you use k to kill the line for a directory file which you had inserted in the Dired buffer as a subdirectory (see Subdirectories in Dired), it removes the subdirectory listing as well. Typing C-u k on the header line for a subdirectory also removes the subdirectory line from the Dired buffer.

The g command brings back any individual lines that you have killed in this way, but not subdirectories—you must use i to reinsert a subdirectory.

The files in a Dired buffers are normally listed in alphabetical order by file names. Alternatively Dired can sort them by date/time. The Dired command s ( dired-sort-toggle-or-edit) switches between these two sorting modes. The mode line in a Dired buffer indicates which way it is currently sorted—by name, or by date.

C-u s switches RET lets you specify a new value for dired-listing-switches.