Next: Flagging Many Files, Previous: Dired Navigation, Up: Dired
One of the most frequent uses of Dired is to first flag files for deletion, then delete the files that were flagged.
dired-flag-file-deletion
).
dired-unmark
).
dired-unmark-backward
).
dired-do-flagged-delete
).
You can flag a file for deletion by moving to the line describing
the file and typing d (dired-flag-file-deletion
). The
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 prefix argument serves as a
repeat count; a negative count means to flag preceding files.
If the region is active, the d command flags all files in the region for deletion; in this case, the command does not move point, and ignores any prefix argument.
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>.
u (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. A numeric prefix argument to
either command serves as a repeat count, with a negative count meaning
to unflag in the opposite direction. If the region is active, these
commands instead unflag all files in the region, without moving point.
To delete flagged files, type x
(dired-do-flagged-delete
). This command 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.
If you change the variable delete-by-moving-to-trash
to
t
, the above deletion commands will move the affected files or
directories into the operating system's Trash, instead of deleting
them outright. See Misc File Ops.