One of the most frequent uses of Dired is to first flag files for deletion, then delete the files that were flagged.
You can flag a file for deletion by moving to the line describing
the file and typing d (
deletion flag is visible as a ‘D’ at the beginning of the line.
This command moves point to the next line, so that repeated d
commands flag successive files. A numeric argument serves as a repeat
The reason for flagging files for deletion, rather than deleting
files immediately, is to reduce the danger of deleting a file
accidentally. Until you direct Dired to delete the flagged files, you
can remove deletion flags using the commands u and <DEL>.
dired-unmark) works just like d, but removes
flags rather than making flags. <DEL>
dired-unmark-backward) moves upward, removing flags; it is
like u with argument −1.
To delete the flagged files, type x
dired-do-flagged-delete). This command first displays a list
of all the file names flagged for deletion, and requests confirmation
with yes. If you confirm, Dired deletes the flagged files, then
deletes their lines from the text of the Dired buffer. The Dired
buffer, with somewhat fewer lines, remains selected.
If you answer no or quit with C-g when asked to confirm, you return immediately to Dired, with the deletion flags still present in the buffer, and no files actually deleted.
You can delete empty directories just like other files, but normally
Dired cannot delete directories that are nonempty. If the variable
dired-recursive-deletes is non-
nil, then Dired can
delete nonempty directories including all their contents. That can
be somewhat risky.
On some systems, there is a facility called the “Trash” or
“Recycle Bin”, but Emacs does not use it by default. Thus,
when you delete a file in Dired, it is gone forever. However, you can
tell Emacs to use the Trash for file deletion, by changing the
t. See Misc File Ops, for more information about the Trash.